Ok. I've got my hardware tested with this basic code. I figured out that I could write a decimal number in my shiftOut code, and it would convert to binary and turn on the lights I wanted to turn on. Great. Hardware all works as it should. However, I do realize there are much simpler ways than writing in decimal values.
////Pin connect to Latch
const int latchPin = 8;
////Pin connected to Clock
const int clockPin = 12;
////Pin connected to Data
const int dataPin = 11;
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop() {
// take the latchPin low so
// the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, 0);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
// pause before next value:
delay(100);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 1);
digitalWrite(latchPin, HIGH);
delay(100);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 3);
digitalWrite(latchPin, HIGH);
delay(100);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 7);
digitalWrite(latchPin, HIGH);
delay(100);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 15);
digitalWrite(latchPin, HIGH);
delay(100);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 31);
digitalWrite(latchPin, HIGH);
delay(100);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 63);
digitalWrite(latchPin, HIGH);
delay(100);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 127);
digitalWrite(latchPin, HIGH);
delay(100);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 255);
digitalWrite(latchPin, HIGH);
delay(3000);
}
I tried to hook up a second register, and just add another shiftOut in the code (i.e. the value 511), thinking that the process would have to go through the first register first before it sent information from the serial out into the serial in of the second register. Of course, to my dissapointment, this was incorrect. The LED on the second register was turned on the same time the first LED on the first register was turned on.
My ultimate goal here is to use a pressure transducer (0-5000 psi, 1-5vdc output) to control 50 LED's, using 7 registers. Each LED will represent 100 psi. As the pressure rises, I want all LED's that have been "passed" to remain on. Example: If I have 1000 psi, I want 10 LED's on.
The stump I've hit is which is the best (least amount of code) way to achieve this. I've read the example codes provided in the shiftOut tutorial. I noticed there are arrays in one of them, and I thought this might be the answer, however, case statements with a map of my transducer range seems like it might be easier for me.
At this point though, I mainly need to know how to delay information to the second register until the first is "filled" when turning the LED's on, and the opposite sequence when turning them off.
Thanks in advance for the help.