Hi, I'm new to using shift registers, trying to turn on and off some LEDs for a set duration, basically ' / if (____== HIGH) check if LED is ON / ' what do I fill in for this portion of code?
// put your main code here, to run repeatedly:
//the pins we are using
int clearPin = 5;
int latchPin = 6;
int clockPin = 7;
int dataPin = 8;
const unsigned long onDuration_0 = 1000;
unsigned long previousTime_0 = 0;
const unsigned long offDuration_0 = 3000;
const unsigned long onDuration_1 = 2000;
unsigned long previousTime_1 = 0;
const unsigned long offDuration_1 = 5000;
const unsigned long onDuration_2 = 3000;
unsigned long previousTime_2 = 0;
const unsigned long offDuration_2 = 1000;
byte register1 = 0;
void setup() { //runs once at startup
//set all the pins used to talk to the chip
//as output pins so we can write to them
pinMode(clearPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
digitalWrite(clearPin, LOW); //Pin is active-low, clears shift register
digitalWrite(clearPin, HIGH); //Clear pin is inactive / take the latchPin low so the LEDs don't change while we are writing data
}
void loop(){
/*Updates frequently*/
unsigned long currentTime = millis();
/* if (____== HIGH) check if LED is ON */
if (currentTime - previousTime_0 >= onDuration_0) {
for (int x = 0; x < 8; x++) { //THIS SELECTS PORT 0-7 ON YOUR SHIFT REGISTER
bitWrite(register1,0,LOW); // PUT LED 0 ON, shift register 1
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, register1);
digitalWrite(latchPin, HIGH);}
/*Update timer for next event*/
previousTime_0 = currentTime;
}
/*else { */
if (currentTime - previousTime_0 >= offDuration_0) {
for (int x = 0; x < 8; x++) { //THIS SELECTS PORT 0-7 ON YOUR SHIFT REGISTER
bitWrite(register1,0,HIGH); // PUT LED 0 ON, shift register 1
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, register1);
digitalWrite(latchPin, HIGH);}
/*Update timer for next event*/
previousTime_0 = currentTime;
}
/* if (____== HIGH) */
if (currentTime - previousTimeOn_1 >= onDuration_1) {
for (int x = 0; x < 8; x++) { //THIS SELECTS PORT 0-7 ON YOUR SHIFT REGISTER
bitWrite(register1,1,LOW); // PUT LED 0 ON, shift register 1
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, register1);
digitalWrite(latchPin, HIGH);}
/*Update timer for next event*/
previousTime_1 = currentTime;
}
/*else { */
if (currentTime - previousTime_0 >= offDuration_1) {
for (int x = 0; x < 8; x++) { //THIS SELECTS PORT 0-7 ON YOUR SHIFT REGISTER
bitWrite(register1,1,HIGH); // PUT LED 0 ON, shift register 1
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, register1);
digitalWrite(latchPin, HIGH);}
/*Update timer for next event*/
previousTime_1 = currentTime;
}
}