Created
December 23, 2013 22:21
-
-
Save darach/8105824 to your computer and use it in GitHub Desktop.
Loop through 00 .. 99 with a pair of IV-16 numitron's
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Pair of IV-16 Numitron's daisy chained on a pair of 74HC595 shift registers. | |
* This sketch simply counts from 00 to 99 repeatedly. Numitron's are wired as | |
* follows: | |
* | |
* +-f-+ 0b 00 00 00 00 | |
* e a -> -d cg ef ba | |
* +-g-+ | |
* d b | |
* +-c-+ | |
*/ | |
const int latchPin = 8; // 74HC595:ST_CP | |
const int clockPin = 12; // 74HC595:SH_CP | |
const int dataPin = 11; // 74HC595:DS | |
// | |
// Digit encoding with -dcgefba pin mapping | |
uint8_t DIGITS[] = { | |
0b00010000, // 0 | |
0b01111100, // 1 | |
0b00001010, // 2 | |
0b01001000, // 3 | |
0b01100100, // 4 | |
0b01000001, // 5 | |
0b00000001, // 6 | |
0b01111000, // 7 | |
0b00000000, // 8 | |
0b01100000 // 9 | |
}; | |
void setup() { | |
pinMode(latchPin, OUTPUT); | |
pinMode(dataPin, OUTPUT); | |
pinMode(clockPin, OUTPUT); | |
clear(); | |
delay(5000); | |
} | |
void loop() { | |
for (int i = 0; i < 100; i++) { | |
display(i); | |
delay(1000); | |
} | |
} | |
void clear() { | |
digitalWrite(latchPin, LOW); | |
shiftOut(dataPin, clockPin, LSBFIRST, 255 | 0b10000000); | |
shiftOut(dataPin, clockPin, LSBFIRST, 255 | 0b10000000); | |
digitalWrite(latchPin, HIGH); | |
} | |
void display(int i){ | |
digitalWrite(latchPin, LOW); | |
shiftOut(dataPin, clockPin, LSBFIRST, DIGITS[(int)(i / 10)] | 0b10000000); | |
shiftOut(dataPin, clockPin, LSBFIRST, DIGITS[(int)(i % 10)] | 0b10000000); | |
digitalWrite(latchPin, HIGH); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment