My initial test of my multiple display set up resulted in disaster: Don't hook up your ULN2003 with reverse voltage! Now it just spits out random oscillations on its outputs and such resulting in only one line lighting up. I might also not be understanding how my shiftOut() is working, the order of the bits and such.
More tomorrow when I can get a new uln2003...
Here is my code in case it seems like I am missing anything there?
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
int ledPin = 13;
byte firstByte[] = { 8, 16, 8,16,8,16, 8, 16};
byte secondByte[] = { 255, 255, 255,255,255,255, 255, 255};
byte thirdByte[] = { 255, 255, 255,255,255,255, 255, 255};
byte fourthByte[] = { 8,8,8,8,8,8,8,8};
// { 0,0,0,0,0,0,0,0 }
int sensorPin = A7; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(ledPin, LOW);
for (int i=0 ; i < 8 ; i++){
digitalWrite(ledPin, LOW);
sensorValue = analogRead(sensorPin);
/*
Serial.print(F("i"));
Serial.println(i);
Serial.print(F("First Byte"));
Serial.println(firstByte[i]);
Serial.print(F("Second Byte"));
Serial.println(secondByte[i]);
*/
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, firstByte[i]);
shiftOut(dataPin, clockPin, MSBFIRST, secondByte[i]);
shiftOut(dataPin, clockPin, MSBFIRST, thirdByte[i]);
shiftOut(dataPin, clockPin, MSBFIRST, fourthByte[i]);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
// pause before next value:
delay(sensorValue);
//digitalWrite(ledPin, HIGH);
/*
digitalWrite(ledPin, HIGH);
delay(0.001);
*/
}
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.