forked from tardate/LittleArduinoProjects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShifty.ino
36 lines (28 loc) · 908 Bytes
/
Shifty.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
Shifty
Drive 8 LEDs with 3 pins using a 74HC595 shift register.
For info and circuit diagrams see https://github.com/tardate/LittleArduinoProjects/tree/master/playground/Shifty
*/
const int latchPin = 10; // latch pin (ST_CP)
const int clockPin = 11; // clock pin (SH_CP)
const int dataPin = 8; // data pin (DS)
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
// a simple loop to light the 8 LEDs in sequence
for(int bitToSet; bitToSet < 8; bitToSet++) {
registerWrite(bitToSet, HIGH);
delay(300);
}
}
// Command: set +whichBit+ on the shift register to +whichState+
void registerWrite(int whichBit, int whichState) {
byte bitsToSend = 0;
digitalWrite(latchPin, LOW);
bitWrite(bitsToSend, whichBit, whichState);
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);
digitalWrite(latchPin, HIGH);
}