I wanted to quickly post a short sketch that one of the early users put together to play with the 74HC595 shift register and LEDs on the I2C and SPI Education Shield using an Arduino Uno. In essence, Peter has developed a Larson Scanner, but with a little twist that I think is really cool, certainly nothing that I would have come up with from a creativity perspective. It’s very subtle, but effective.
Enjoy!
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 37 38 39 40 |
#define oeP 5 #define clockP 6 #define latchP 7 #define dataP 8 byte bitPosition[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; void setup() { pinMode (oeP, OUTPUT); pinMode (clockP, OUTPUT); pinMode (latchP, OUTPUT); pinMode (dataP, OUTPUT); digitalWrite (oeP, LOW); } void loop() { for (int pos = 7; pos > 0; pos--) ledOn (pos); for (int pos = 0; pos < 7; pos++) ledOn (pos); } void ledOn (int pos) { digitalWrite (latchP, LOW); shiftOut (dataP, clockP, MSBFIRST, bitPosition[pos]); digitalWrite (latchP, HIGH); delay ((sqrt (((float)8 - pos) / 8) - sqrt (((float)7 - pos) / 8)) * 490); } |