Latching Remote LEDS
IRobot2
Posts: 164
Here is what I am working with:
I have 16 momentary pushbuttons connected to a prop (pins 1-16). This prop sends serial data to remote prop that has 16 corresponding LEDS connected to it (pins 1-16).
Here is what I want it to do:
Every time a button is pressed it will hold in the corresponding LED for 5 seconds.
Here is the problem I am having:
Since I do not have 16 cogs, I cannot think of the correct *software* way to latch the LEDs on in such a way that pushing buttons 1,2,3,4 will turn on LEDs 1,2,3,4 at the same time. (Using wait statements to keep an LED on of coarse keeps the other LEDs from lighting at once. )
The catch:
If button 1 is hit 3 times within the 5 second holding period, it still needs to go off in 5 seconds. (Not continue to keep adding 5 seconds).
Can anyone point me in the right direction? Can this even be done?
Thanks for all of your help! -Alex
I have 16 momentary pushbuttons connected to a prop (pins 1-16). This prop sends serial data to remote prop that has 16 corresponding LEDS connected to it (pins 1-16).
Here is what I want it to do:
Every time a button is pressed it will hold in the corresponding LED for 5 seconds.
Here is the problem I am having:
Since I do not have 16 cogs, I cannot think of the correct *software* way to latch the LEDs on in such a way that pushing buttons 1,2,3,4 will turn on LEDs 1,2,3,4 at the same time. (Using wait statements to keep an LED on of coarse keeps the other LEDs from lighting at once. )
The catch:
If button 1 is hit 3 times within the 5 second holding period, it still needs to go off in 5 seconds. (Not continue to keep adding 5 seconds).
Can anyone point me in the right direction? Can this even be done?
Thanks for all of your help! -Alex
Comments
This one COG simply needs an endless loop that's doing the following:
1. Check if we received a new pushbutton message throm the other prop
2. If so, check whether that button has already been pushed
3. If not store the value of the counter in an array and switch the corresponding LED on
4. Loop over all elements of the array
5. If the current LED is on, check when it has been switched on ( subtract counter vale stored in the array from the actual cnt )
6. If the difference is 5*clockfreq or bigger then switch off the LED
Hope that's enough to point you in the right direction. If not continue asking.
I agree with Mag and here's a little method that lets you pass the start and end points of your LED group (they must be contiguous), as well as the address of an array that holds the timer for each LED.
The attached program runs on a demo board. When you press a key (I'm using PST) it will light the LED for 5 seconds. Note that if the LED is already lit then its timer will be reset to 5 seconds (this logic is easy to change).