high guys,
I'm am fairly new to the world of electronics/ arduino.
I am trying to make 8 led lights light up sequentially once the PIR sensor has been tripped however, the lights all flash and shouldnt, please help and see code below:
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
int pirPin = 3;
int val = 0;
const byte COL_COUNT = 8;
unsigned char sequence[COL_COUNT] = {B00000001, B00000011, B00000111, B00001111, B00011111, B00111111, B01111111, B11111111};
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(pirPin, INPUT);
}
void loop()
{
val = digitalRead(pirPin);
if (val == HIGH)
{
int col_data = 0;
for (int col = 0; col < COL_COUNT; col++)
bitWrite(col_data, col, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, col_data);
digitalWrite(latchPin, HIGH);
delay(300);
}
delay(2500);
int col_data = 0;
for (int col = 0; col < COL_COUNT; col++)
{
bitWrite(col_data, col, LOW);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, col_data);
digitalWrite(latchPin, HIGH);
delay(600);
}
}