just playing this morning

johnlong

Senior Member
Hi All
Was just having a play this morning (trying to stick pin into scratchpad)
and ended in doing the following not what I was after but thourght
I wonder if so I did and found out it toggles the pins nicely

Code:
dirsB=%11111111
pin:
pinsB=%00111100

main:
b0=0
do 
	pinsB= dirsB-pinsB
	pause 1000
	inc b0
loop until b0=9
inc b1
if b1=1 then
	pinsB=%10101010	
	goto main
	elseif b1=2 then
		pinsB=%01010101
		goto main
		elseif b1=3 then
			pinsB=%11001100
			goto main
			elseif b1=4 then
				pinsB=%11000011
				goto main
				elseif b1=5 then
					b1=0
					goto pin
					endif
would look good on an LED hat:cool:
regards
john
 
Last edited:

jims

Senior Member
Hi All
Was just having a play this morning (trying to stick pin into scratchpad)
and ended in doing the following not what I was after but thourght
I wonder if so I did and found out it toggles the pins nicely

Code:
dirsB=%11111111
pin:
pinsB=%00111100

main:
b0=0
do 
	pinsB= dirsB-pinsB
	pause 1000
	inc b0
loop until b0=9
inc b1
if b1=1 then
	pinsB=%10101010	
	goto main
	elseif b1=2 then
		pinsB=%01010101
		goto main
		elseif b1=3 then
			pinsB=%11001100
			goto main
			elseif b1=4 then
				pinsB=%11000011
				goto main
				elseif b1=5 then
					b1=0
					goto pin
					endif
would look good on an LED hat:cool:
regards
john
johnlong...just what is an "LEDhat"?? Thank you, JimS
 

jims

Senior Member
I just googled "LED hat"....now I know. Guess this old fella is not up to date with all these new fangled things. Jims
 

westaust55

Moderator
Hello John,

Great to see someone who is willing to give an idea a try out first.

If I might make a suggestion on code formatting, better to try an keep all the related ELSEIF statements with the same level of indenting.
Also try to keep only labels staring in the left most column.
While the PE is quite flexible it does make for easier reading and seeing the flow at a glance.
Here by way of example is your code:
Code:
	dirsB=%11111111
pin:
	pinsB=%00111100

main:
	b0=0
	do 
		pinsB= dirsB-pinsB
		pause 1000
		inc b0
	loop until b0=9
	inc b1
	if b1=1 then
		pinsB=%10101010	
		goto main
	elseif b1=2 then
		pinsB=%01010101
		goto main
	elseif b1=3 then
		pinsB=%11001100
		goto main
	elseif b1=4 then
		pinsB=%11000011
		goto main
	elseif b1=5 then
		b1=0
		goto pin
	endif

Finally there are often more than 1 way to do something. Try this and see if it performs the same way with half the program space:

Code:
	dirsB=%11111111
pin:
	pinsB=%00111100

main:
	DO
	  b0=0
	  do 
		pinsB= dirsB-pinsB
		pause 1000
		inc b0
	  loop until b0=9

	  b1 = b1 + 1 // 5
	
	  LOOKUP b1, (%10101010,%01010101,%11001100,%11000011,%00111100), pinsB
	LOOP
 
Last edited:

johnlong

Senior Member
Hi westaust
I like that b1=b1+1//5 stuck it into PE to see what it does
and found it gave a counter for 1 to 4
cool
If you change it to b1=b1+2//5 it gives you results of 1,3,2,4
that being stuck into my list of commands for future head scratches
john
 

westaust55

Moderator
Hi westaust
I like that b1=b1+1//5 stuck it into PE to see what it does
and found it gave a counter for 1 to 4
cool
If you change it to b1=b1+2//5 it gives you results of 1,3,2,4
that being stuck into my list of commands for future head scratches
john
Hello John,

the // is the Modulus (remainder) operator.
so with // 5, from 0 to 4 when you divide by 5 you get the input, when you have 5 as the input 5/5 = 1 and no remainder so you get 0. with a higher number, e.g. 6, 6 // 5 = 1 and a remainder of 1.

With your "test" using b1=b1+2//5
for b1= 0 and increment you have
b1 = 0 ==> 0 + 2 = 2 then //5 ==> 2
b1 = 1 ==> 1 + 2 = 3 then //5 ==> 3
b1 = 2 ==> 2 + 2 = 4 then //5 ==> 4
b1 = 3 ==> 3 + 2 = 5 then //5 ==> 0
b1 = 4 ==> 4 + 2 = 6 then //5 ==> 1
b1 = 5 ==> 5 + 2 = 7 then //5 ==> 2
etc

so with starting b1=b1+2//5 and b1 = 0
the resulting sequence is 2, 4, 1, 3, 0 repeating.
 
Top