Czech republic
Offline
Newbie
Karma: 0
Posts: 24
|
 |
« on: June 17, 2011, 05:50:22 am » |
Hi, I am quite a newbie in Arduino programming and I have (for you sure simple) question. I want to turn on or off LEDs attached to HCF4094BE shift register. I have tried this http://senster.com/blog/wp-content/uploads/2009/02/expanding_outputs.pdf and it works.But I want to light a LED for 1s when the pushbutton is pressed and when it is pressed again it will light next led.I do not understand much the code so I need this help. Thanks for answers and please apologize my English if it is not good eneugh 
|
|
|
|
|
Logged
|
|
|
|
|
Massachusetts, USA
Offline
Tesla Member
Karma: 96
Posts: 6376
|
 |
« Reply #1 on: June 17, 2011, 06:52:00 am » |
Perhaps the code would be easier to follow if it was split up more. I hope this helps: void loop() { unsigned int outputpattern = 1; //stores the output pattern as an unsigned int, that is, two bytes
for (int i=0 ; i< 16; i++) { // Repeat 16 timees setOutputs(outputpattern); // Display the pattern delay(100); // Pause 0.1 seconds outputpattern = outputpattern << 1; // Change the pattern } }
void setOutputs(unsigned int pattern) { byte pattern_MSB = pattern >> 8; //extract the MSB by shifting 8 bits to the right byte pattern_LSB = pattern;
// Shift the data out 8 bits at a time. shiftOut(dataPin, clockPin, MSBFIRST, pattern_MSB); shiftOut(dataPin, clockPin, MSBFIRST, pattern_LSB);
digitalWrite(latchPin, 1); // flick the latch to put the data on the output pins delay(1); digitalWrite(latchPin, 0); }
|
|
|
|
|
Logged
|
|
|
|
|
Czech republic
Offline
Newbie
Karma: 0
Posts: 24
|
 |
« Reply #2 on: June 17, 2011, 08:07:24 am » |
So I made now this // program to test using two 4094 shift registers // // if everything is correct, it will light up one LED at a time // int latchPin = 10; int clockPin = 11; int dataPin = 12;
int butt = 7; byte but = LOW;
void setup() { pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); digitalWrite(latchPin, 0); //make sure data isn't latched } void loop() { unsigned int outputpattern = 1; //stores the output pattern as an unsigned int, that is, two bytes
but = digitalRead(butt); if (but == HIGH){ outputpattern = outputpattern << 1; // Change the pattern delay(500); } for (int i=0 ; i < 10; i++){ setOutputs(outputpattern); // Display the pattern delay(100); // Pause 0.1 seconds } }
void setOutputs(unsigned int pattern) { byte pattern_MSB = pattern >> 8; //extract the MSB by shifting 8 bits to the right byte pattern_LSB = pattern;
// Shift the data out 8 bits at a time. shiftOut(dataPin, clockPin, MSBFIRST, pattern_MSB); shiftOut(dataPin, clockPin, MSBFIRST, pattern_LSB);
digitalWrite(latchPin, 1); // flick the latch to put the data on the output pins delay(1); digitalWrite(latchPin, 0); } but something is wrong.When i press the button, it will light the next led but when I press it again nothing happen and in a while the first led is on again...Do you now why?
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 277
Posts: 25517
Solder is electric glue
|
 |
« Reply #3 on: June 17, 2011, 09:40:38 am » |
Do you now why? Yes, because that is the way you have written it. I haven't looked at all the code but this bit:- for (int i=0 ; i < 10; i++){ setOutputs(outputpattern); // Display the pattern delay(100); // Pause 0.1 seconds } Just does the same thing 10 times because the variable outputpattern doesn't change during the loop.
|
|
|
|
|
Logged
|
|
|
|
|
Czech republic
Offline
Newbie
Karma: 0
Posts: 24
|
 |
« Reply #4 on: June 17, 2011, 09:50:45 am » |
But even if I remove the for loop it does the same thing...
|
|
|
|
|
Logged
|
|
|
|
|
Massachusetts, USA
Offline
Tesla Member
Karma: 96
Posts: 6376
|
 |
« Reply #5 on: June 17, 2011, 10:19:10 am » |
It does everything inside loop() repeatedly.
The first thing it does inside loop() is set the pattern to 0000000000000001. That is why it is going back to the first light.
You have a delay of half a second after you change the pattern and before you display the pattern.
Then there is another 0.1 second delay before you repeat everything.
|
|
|
|
|
Logged
|
|
|
|
|
Czech republic
Offline
Newbie
Karma: 0
Posts: 24
|
 |
« Reply #6 on: June 17, 2011, 10:23:11 am » |
OK than how do I make the next led ON when the button is pressed?
|
|
|
|
|
Logged
|
|
|
|
|
Massachusetts, USA
Offline
Tesla Member
Karma: 96
Posts: 6376
|
 |
« Reply #7 on: June 17, 2011, 10:31:34 am » |
OK than how do I make the next led ON when the button is pressed?
Move the initialization of 'outputpattern' to some place outside of any function. You can put that line just above setup().
|
|
|
|
|
Logged
|
|
|
|
|
Czech republic
Offline
Newbie
Karma: 0
Posts: 24
|
 |
« Reply #8 on: June 17, 2011, 10:35:48 am » |
Thank all off you.I have already done this before but my pullup resistor on the button was not properly connected.Thank you one more time 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 10
|
 |
« Reply #9 on: May 31, 2012, 07:53:39 am » |
Hello, we are working on an LED sign board, which is very similar to what you have running, using the HCF4094be. The default code does make the sign light a 'column' of lights, but we would like to be able to do pixel by pixel so we can actually put letters or something besides a scrolling column.  We have basically a 24 column by 7 row panel (there are 4 panels linked together), and we can either light up a big block of LEDs that scroll, or a single line that scrolls, but we cannot figure out how to get individual pixels to scroll. I can provide pictures and more details if needed. We are extremely new to arduino, LED, and HCF4094 stuff, so thank you in advance for all that you have helped us with so far (even though this is our first post  ).
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 277
Posts: 25517
Solder is electric glue
|
 |
« Reply #10 on: May 31, 2012, 08:16:25 am » |
but we cannot figure out how to get individual pixels to scroll. Give it one clock pulse and then toggle the strobe line.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 10
|
 |
« Reply #11 on: May 31, 2012, 08:48:51 am » |
Thank you for your amazingly fast reply!! I'm not sure how to do that, however. We have a Data/Clock/Strobe pin, but in the 'default' code from the PDF above, it uses a 'latch' pin. So, we just changed the one line in code to say that the latch pin is the same as the strobe pin on the arduino. I HATE being such a NOOB with this stuff. I have gone through all the tutorials with my arduino with steppers and stuff, but this thing is way different. Thanks again for your input!!! I really appreciate it!!
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 277
Posts: 25517
Solder is electric glue
|
 |
« Reply #12 on: May 31, 2012, 09:11:59 am » |
I don't know how you have wired it up so I can't give precise pin numbers. You did not provide any link to a schematic nor did you post any code.
Give it one clock pulse - put the clock pin high, then put it low using the digitalWrite() function toggle the strobe line. - put the strobe pin high, then put it low using the digitalWrite() function
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 10
|
 |
« Reply #13 on: May 31, 2012, 09:46:40 am » |
Again, thank you for your time and input! Here are some pictures that we have posted on google: http://picasaweb.google.com/rossb2645/LEDLightBoard?feat=email#I tried playing with the line : pattern_LSB = outputpattern & B11111111; thinking that each '1' was a row, but that had no effect on the output to the sign. Thanks again for your time and input!! We are running this code: // program to test using two 4094 shift registers // // if everything is correct, it will light up one LED at a time // int latchPin = 11; int clockPin = 10; int dataPin = 9; void setup() { pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); digitalWrite(latchPin, 0); //make sure data isn't latched } void loop() { unsigned int outputpattern =1; //stores the output pattern as an unsigned int, that is, two bytes int pattern_LSB; //the least significant byte (LSB) of the pattern int pattern_MSB; //the most significant byte (MSB) of the pattern for (int i=0 ; i< 16; i++){ pattern_MSB = outputpattern >>8; //extract the MSB of the pattern by shifting all the bits over by 8 pattern_LSB = outputpattern & B11111111; //extract the LSB of the pattern by bitwise AND shiftOut(dataPin, clockPin, MSBFIRST, (byte) pattern_MSB); shiftOut(dataPin, clockPin, MSBFIRST, (byte) pattern_LSB); digitalWrite(latchPin, 1); // flick the latch to put the data on the output pins delay(1); digitalWrite(latchPin, 0); delay(100); outputpattern = outputpattern <<1; // shift the outputpattern left by one bit } }
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 277
Posts: 25517
Solder is electric glue
|
 |
« Reply #14 on: May 31, 2012, 10:13:12 am » |
digitalWrite(latchPin, 0); //make sure data isn't latched should be digitalWrite(latchPin, LOW); //make sure data isn't latched To be strictly correct. I tried playing with the line : pattern_LSB = outputpattern & B11111111; Waste of time playing with the B11111111 all that does is to isolate the least significant byte fro the rest of the bit pattern outputpattern. You should write this:- pattern_LSB = outputpattern & 0xff To make it easier for grown ups to read. Using a binary bit pattern is a bit pants. However this code appears to do what you want to do. It outputs the patterns of on and off stored in outputpattern. Then at the end this line:- outputpattern = outputpattern <<1; // shift the outputpattern left by one bit Changes what you put out by one pixel and it outputs it again, thus causing it to scroll that bit pattern. The line unsigned int outputpattern =1; Is where you set up the pattern you want to display, so for example:- unsigned int outputpattern =0xaaaa; will turn on every other LED, or unsigned int outputpattern =0xff00; will turn on the top 8 LEDs and leave off the bottom 8 ( or the other way round because a photo is NOT a schematic )
|
|
|
|
|
Logged
|
|
|
|
|
|