Hi all, I was hoping to get some help with, what I think, is something very simply but i'm just not seeing it.
The first shift register is connected to 8 LED's, each represents and hour from 0 hours (Q0) to 7 hours (Q7), the second shift register has 5 LED's representing hours 8 (Q0) to 12 Q4). I have an RTC DS3231 providing the time. The LED's will be incorporated into a clock face and light to indicate the hour.
The first shift register works, hours 0 to 7, when the hour goes above 7, I get no lights in the first regster (good, that's what I'd like) but I also get no lights in the 2nd register either (and variable a and b are both zero in the serial monitor). When I replace the variables a and b with actual numbers to simulae what I want the variables to be, it seems to work fine.
I have a feeling I'm missing someting about variables being used with bitshift, or I'm not understanding how bitshift works with 2 registers.
The circuit I'm using is as per this link arduino uno - Multiple shift registers, 16 bit numbers - Arduino Stack Exchange
I've checked the connections twice to ensure no wiring errors.
The code I'm using is:
#include <DS3231.h>
int latchPin = 7;
int clockPin = 8;
int dataPin = 9;
DS3231 rtc(SDA, SCL);
Time t;
uint8_t hours1 = 0;
uint8_t hours2 = 0;
void setup() {
Serial.begin(115200);
pinMode (latchPin, OUTPUT);
pinMode (clockPin, OUTPUT);
pinMode (dataPin, OUTPUT);
rtc.begin();
}
void loop() {
t = rtc.getTime();
//Serial.println (t.hour);
delay(50);
int a;
int b;
if (t.hour > 7) {
a = 0;
b = 1;
hours2 = t.hour - 8;
Serial.print(F("t.hour="));
Serial.print(t.hour);
Serial.print(F("Hours2="));
Serial.println(hours2);
}
else
a = 1;
b = 0;
hours1 = t.hour;
Serial.print(F("variable a = "));
Serial.println(a);
Serial.print(F("variable b = "));
Serial.println(b);
Serial.println(F("______________________________________________"));
Serial.print(F("Hours1="));
Serial.println(hours1);
Serial.print(F("Hours1="));
Serial.println(hours2);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, b << hours2); //Certainly seems to work ok for the 1st register hours 0-7 recheck wiring of 2nd shift register.
shiftOut(dataPin, clockPin, MSBFIRST, a << hours1);
digitalWrite(latchPin, HIGH);
delay(20);
}
I'm sure tis is someting really basic, would really appreaciate ssome help, thanks.
Phil