Need Help with coding
jknightandkarr
Posts: 234
I need some help.· I got this project, that I'm trying to duplicate, except mine will have 9 buttons not 8.
There's 9 buttons & 2 leds on each side of each button for a total of 18 LEDs. Now there's 2 displays total, making 18 buttons & 36 LED's total. Now I'm putting all the buttons right on the propeller, and driving the leds from 5 shift registers. I've got my initial program designed, but I find myself having problems now. Now, the top 2 leds on each side, the ones with the arrows, highlight what side is active. My problem is, is I used the I/O pins to look for inputs & send the output to an I/O pin. Now since I need to use shift registers to run the leds my old program won't work as designed. I need to shift 36 bits of H/L information to the shift registers, not too much of a problem, but I've added variables for each LED and I need to be able to update each one by itself, not an issue here, but I'm clueless how to combine them all into one variable that's then sent to the shift registers, the soul purpose to turn on or off each led using the buttons. I got how to latch them on or off, time them to stay on for like 5 seconds then turn on, or just come on when the appropriate button is pressed & then off when released, this is easy, I just need to combine all 36 of my led variable into one variable, so I can send that to my shift registers. Can anyone help?
Joe
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm going insaine. It's SOOOOOO much fun. lol
There's 9 buttons & 2 leds on each side of each button for a total of 18 LEDs. Now there's 2 displays total, making 18 buttons & 36 LED's total. Now I'm putting all the buttons right on the propeller, and driving the leds from 5 shift registers. I've got my initial program designed, but I find myself having problems now. Now, the top 2 leds on each side, the ones with the arrows, highlight what side is active. My problem is, is I used the I/O pins to look for inputs & send the output to an I/O pin. Now since I need to use shift registers to run the leds my old program won't work as designed. I need to shift 36 bits of H/L information to the shift registers, not too much of a problem, but I've added variables for each LED and I need to be able to update each one by itself, not an issue here, but I'm clueless how to combine them all into one variable that's then sent to the shift registers, the soul purpose to turn on or off each led using the buttons. I got how to latch them on or off, time them to stay on for like 5 seconds then turn on, or just come on when the appropriate button is pressed & then off when released, this is easy, I just need to combine all 36 of my led variable into one variable, so I can send that to my shift registers. Can anyone help?
Joe
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm going insaine. It's SOOOOOO much fun. lol
Comments
This is one long variable and you can set specific locations within that variable to on/off or whatever.
Here is a search of this forum for the words array and propeller...
http://www.google.com/search?hl=en&lr=&q=propeller+array+site%3Aforums.parallax.com&btnG=Search&aq=f&aqi=&aql=&oq=&gs_rfai=
each leds is represented by a byte-variable
set to value zero or one
now you count up an index-variable in a loop
shiftvar := led[noparse][[/noparse] index ]*2^index
for debugging I recommend to add some lines that do serial output
using the ".bin" command of the fullduplexserial-object
".bin" outputs binary numbers
so that you can analyse if the bits are set to zero or one the right way
best regards
Stefan
^ as far as I remember is not the "to the power of" operator, it's the exclusive or. So the real code that has to be used is:
shiftvar |= led[noparse][[/noparse] index ] * |< index
Another way would be to shift in the bits into the shiftvar:
shiftvar <<=1
shiftvar |= led[noparse][[/noparse] index ]
In both cases the shiftvar needs to be initialized with 0 in front of the loop and in both cases the led values have to be 0 or 1.
Post Edited (MagIO2) : 5/20/2010 5:39:21 AM GMT
Joe
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm going insaine. It's SOOOOOO much fun. lol