Newbie question..

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 :slight_smile:

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);
  }

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?

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.

But even if I remove the for loop it does the same thing...

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.

OK than how do I make the next led ON when the button is pressed?

owar:
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().

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 :slight_smile:

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 :)).

but we cannot figure out how to get individual pixels to scroll.

Give it one clock pulse and then toggle the strobe line.

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

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
	}
}
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.

Weird, eh?

I do get an every other column (but not pixel).

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.

Alright, we used a program called ExpressPCB to draw this... don't shoot me, as I'm not an electronics person :slight_smile: ... but, this is a really big PDF (size wise, not file wise). https://docs.google.com/open?id=0B1fuI6Mh8iscLXFjMnNBdWhyb1k

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!

I am sorry I don't see how that can ever work.

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?