Reversing flash

Bundu

New Member
Hi -with some excellent help I've got the bug to reverse and beep:

main:

let pins = %01010000 'make pins 6 and 4 high: full ahead!

if pin2 = 1 then left 'if pin 2 goes high then execute the subroutine "left"

if pin7 = 1 then right 'if pin 7 goes high then execute the subroutine "right"

goto main 'return to main routine

left:

let pins = %00000110 'pin 1 and 2 go high and turns on the red LEDs

for b1 =1 to 5 '5 * (50+50) = 500 this regulates the distance reversed

sound 0, (100,50) ' sets piezo tone and length

pause 50 ' pause

let pins = %10100110 'LEDs and motors on

pause 50 'pause

next b1

let pins = %10010110 'pins 1, 2, 4, 7 go high - LED and one motor forward and one back - left turn

pause 1500 ' this regulates the angle turned

goto main 'lights out - full ahead!

right:

let pins = %00000110 'pin 1 and 2 go high and turn on the red LEDs

for b1 =1 to 5 '5 * (50+50) = 500 this regulates the distance reversed

sound 0, (100,50) ' sets piezo tone and length

pause 50 ' pause

let pins = %10100110 'LEDs and motors on

pause 50 'pause

next b1

let pins =%01100110 'pins 1, 5 and 6 go high - LED and one motor forward and one back - right turn

pause 1500 ' this regulates the angle turned

goto main 'full ahead!


However I can't get the LEDs to flash at the same time as in my earlier prog:

led_loop:
let pins = %0000110 'let pins 1 and 2 go high turning both LEDs on
sound 0, (100,50) ' sets piezo tone and length
pause 50 ' pause
let pins = %00000000 'turn LEDs off
pause 50 'pause
goto led_loop

Am what I'm asking toocomplex?
 

Technical

Technical Support
Staff member
Simply insert this line after the for b1... lines

let pins = %10100000 'LEDs off but motors on

Then every 50ms (excluding the sound time) the lights will flash. As sound takes a period of time to process the flashes will be uneven - play with the two pause values as you desire to balance things out.
 

Bundu

New Member
Have inserted that bit of code and it is working fine now - i'll hit the books and find out why! Many thanks once again.
 
Top