int latchPin = 12; // pin connected ST_CP of 74HC595
int clockPin = 13; // pin connected SH_CP of 74HC595
int dataPin = 11; // pin connected DS of 74HC595
void setup() {
// put your setup code here, to run once:
// set pins output
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// define one-byte variable to use 8 bits to represent state of 8 LEDs of bar graph
// assigned to 0x01, binary 00000001, indicate one LED light is on
byte x = 0x01;
for(int j = 0; j < 8; j++){
// Output lowlevel to latch pin
digitalWrite(latchPin, LOW);
// send serial data to 74HC595
shiftOut(dataPin, clockPin, LSBFIRST, x);
// Output high level to latch pin, 74HC595 will update data to parallel output pin
digitalWrite(latchPin, HIGH);
// make variable move one bit to the left once, bright LED move one step to the left
x <<= 1;
delay(100); // delay 100 ms
}
}