Simple LED problem
Hi there,
As I was going through the "Robotics with Boe-Bot" manual, I came across a small problem with pulsing LED's. Using the following given code, I can't the 2 LED's I'm using (connected to pins 12 and 13) to pulse simultaneously.
1 Pulses just before the other, for some reason...slightly out of sync. How can I fix this problem?
Also, how to you get it to stop looping or to only loop for a certain amount of time? Even if I turn the power off then back on, it carries on looping.
Thanks [noparse]:)[/noparse]
Post Edited (GPeyton) : 11/13/2008 4:37:40 PM GMT
As I was going through the "Robotics with Boe-Bot" manual, I came across a small problem with pulsing LED's. Using the following given code, I can't the 2 LED's I'm using (connected to pins 12 and 13) to pulse simultaneously.
DEBUG "Program running!" DO PULSOUT 13, 65000 PULSOUT 12, 65000 PAUSE 2000 LOOP
1 Pulses just before the other, for some reason...slightly out of sync. How can I fix this problem?
Also, how to you get it to stop looping or to only loop for a certain amount of time? Even if I turn the power off then back on, it carries on looping.
Thanks [noparse]:)[/noparse]
Post Edited (GPeyton) : 11/13/2008 4:37:40 PM GMT
Comments
I'm going to make an educated guess here and say that your non-synchronous situation is caused by the fact·that the code is serial, meaning, the first PULSEOUT is started then the next.· This will cause one LED to come on before the other making the whole run of both PULSEOUT commands be out-of-sync.
Correcting this?· Again, educated guess...I'd use the feature of the BasicStamp that allows setting groups of pins as either input or output (in this case set them as output) and then the two pins would be driven in parallel.
Check the BasicStamp programming/syntax manual chapter 4 right around page 82 for more info.
Regards,
DJ
I had a look at the manual, and found something relating to what you said, but am totally lost in all the jargon (being about a 2 day old beginner!).
Sorry to be so slow!
Thanks again
This will blink both LEDs simultaneously and for a duration of about 65 milliseconds. Commands in PBASIC are always executed sequentially, as in your two PULSOUT commands. The predefined variables dir and out (see the manual for all the variations) let you set the direction and HIGH/LOW state of pins simultaneously. In the above, the pins p12 and p13 are made outputs, and then the outD statement is making them high and low. The % notation means binary.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Exactly what Mr. Allen has said.
DJ
Just one more question: Why do HIGH and LOW commands produce a synchronised result, but PULSE commands produce a non-synchronised result? This is what I found experimentally.
That, and the BS2 is a "Single tasking processor", so the first PULSOUT has to complete before the second PULSOUT can begin. This might not be obvious from the manual, but it is true.