]> git.piffa.net Git - sketchbook_andrea/blob - hardware/shift_register/shift_register_pattern/shift_register_pattern.ino
clean up
[sketchbook_andrea] / hardware / shift_register / shift_register_pattern / shift_register_pattern.ino
1 /* SuperCar like pattern with a shift register.
2    Note: first bit/LED is supposed to be 0 and not 7
3    as in many arduino example sketches.
4    
5  Turning on the outputs of a 74HC595 using an array
6  
7  Hardware:
8  * 74HC595 shift register
9  * LEDs attached to each of the outputs of the shift register
10  */
11
12 int clockPin = 12; //IC Pin 11, Yellow Jumper
13 int dataPin = 11; //IC Pin 14, Blue Jumper
14 int latchPin = 8; //IC Pin 12, Green Jumper
15
16 byte patterns[30] = {
17   B00000001, 100,
18   B00000010, 100,
19   B00000100, 100,
20   B00001000, 100,
21   B00010000, 100,
22   B00100000, 100,
23   B01000000, 100,
24   B10000000, 100,
25   B01000000, 100,
26   B00100000, 100,
27   B00010000, 100,
28   B00001000, 100,
29   B00000100, 100,
30   B00000010, 100
31 };
32
33 int index = 0;
34 int count = sizeof(patterns) / 2;
35
36 void setup() {
37   pinMode(latchPin, OUTPUT);
38   pinMode(clockPin, OUTPUT);
39   pinMode(dataPin, OUTPUT);
40 }
41
42 void loop() {
43   digitalWrite(latchPin, LOW);
44   shiftOut(dataPin, clockPin, MSBFIRST, patterns[index * 2]);
45   digitalWrite(latchPin, HIGH);
46   delay(patterns[(index * 2) + 1]);
47   index++;
48   if (index >= count){
49     index = 0;
50   }
51 }
52