X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=hardware%2Fshift_register%2Fshift_register_pattern%2Fshift_register_pattern.ino;fp=hardware%2Fshift_register%2Fshift_register_pattern%2Fshift_register_pattern.ino;h=d59a2962e0020bf071331c02446105579457598d;hb=2e29cbe13965809a5d3866ccdc12b1d665b54115;hp=0000000000000000000000000000000000000000;hpb=11eb80579bf2e63a8244897614542c917f641a47;p=sketchbook_andrea diff --git a/hardware/shift_register/shift_register_pattern/shift_register_pattern.ino b/hardware/shift_register/shift_register_pattern/shift_register_pattern.ino new file mode 100644 index 0000000..d59a296 --- /dev/null +++ b/hardware/shift_register/shift_register_pattern/shift_register_pattern.ino @@ -0,0 +1,52 @@ +/* SuperCar like pattern with a shift register. + Note: first bit/LED is supposed to be 0 and not 7 + as in many arduino example sketches. + + Turning on the outputs of a 74HC595 using an array + + Hardware: + * 74HC595 shift register + * LEDs attached to each of the outputs of the shift register + */ + +int clockPin = 12; //IC Pin 11, Yellow Jumper +int dataPin = 11; //IC Pin 14, Blue Jumper +int latchPin = 8; //IC Pin 12, Green Jumper + +byte patterns[30] = { + B00000001, 100, + B00000010, 100, + B00000100, 100, + B00001000, 100, + B00010000, 100, + B00100000, 100, + B01000000, 100, + B10000000, 100, + B01000000, 100, + B00100000, 100, + B00010000, 100, + B00001000, 100, + B00000100, 100, + B00000010, 100 +}; + +int index = 0; +int count = sizeof(patterns) / 2; + +void setup() { + pinMode(latchPin, OUTPUT); + pinMode(clockPin, OUTPUT); + pinMode(dataPin, OUTPUT); +} + +void loop() { + digitalWrite(latchPin, LOW); + shiftOut(dataPin, clockPin, MSBFIRST, patterns[index * 2]); + digitalWrite(latchPin, HIGH); + delay(patterns[(index * 2) + 1]); + index++; + if (index >= count){ + index = 0; + } +} +