// 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?
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 :)).
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!!
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
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
}
}
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 )
Along with the photos on the google page, there are two different schmematics of how the board is laid out. The first one is pretty simple and kinda 'dirty'... but the second one is a lot cleaner (it is the last photo... basically a JPG render of VISIO).
I will try what you have posted... thanks a TON for your time and input!!
The changes made did change the pattern output, but it is really different. If I do unsigned int outputpattern = 0xaaaa I do get an every other column (but not pixel).
and the =0xff00 displays a 'block' that slowly dissappears in the middle.
Yes well that is because you have not supplied a schematic so it was not clear what that shift register was driving.
To get an idea of a matrix look at this page:- http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html
displays a 'block' that slowly dissappears in the middle.
Weird, eh?
No it just reflects the way you have wired it up, in other words what signals control what physical position of the LEDs. You can correct it in the wiring or by scrambling the bit pattern you feed it.
What you can see is that there are seven TIP42C transistors that feed each row (and it appears that it pulls to ground). There are two chips, the HCF4094 and teh ULN2003 that are shift registers. The Arduino hooks into the first HCF4094 chip, which then shifts the data down.
The power supply / driver board was already built into the whole system. We are just using the power to drive the board, and slid the Arduino into where the signal comes out of the original board.
Hopefully all that makes sense. Thank again, for your time and input!
You seem to have 4 LEDs connected in series with only a 5V power supply. There is not enough voltage to turn 4 LEDs on.
Secondly you seem to only have two transistors.
Did you read that link I send you before about an LED matrix?
Yeah, there are four of them in an array. We cut the voltage down, cuz we are only running one of four panels... when we do that, if we don't cut the voltage, we end up smoking our arduino. There are 7 transistors, not 2... just ran out of room to draw them all in. Basically, they just repeat down the rows. I can draw them in, if that would be better.
I did look at the matrix website, but I'm still confused... ugghhh... not sure why it has to be so confusing