const byte numeral[10] = {
B11111100, // 0
B01100000, // 1
B11011010, // 2
B11110010, // 3
B01100110, // 4
B10110110, // 5
B10111110, // 6
B11100000, // 7
B11111110, // 8
B11110110, // 9
};
// pins for decimal point and each segment
// DP,G,F,E,D,C,B,A
const int segmentPins[8] = { 2, 11, 10, 5, 4, 3, 8, 9 }; //dp,g,f,e,d,c,b,a
void setup() {
for (int i = 0; i < 8; i++) {
pinMode(segmentPins[i], OUTPUT); // set segment and DP pins to output
}
}
void loop() {
for (int i = 0; i <= 9; i++) {
showdigit(i);
delay(1000);
}
// the last value if i is 10 and this will turn the display off
delay(1000); // pause second with the display off
// Displays a number from 0 through 9 on a 7-segment display
// any value not within the range of 0-9 turns the display off
}
void showdigit(int number) {
boolean isBitSet;
for (int segment = 1; segment < 8; segment++) {
isBitSet = bitRead(numeral[number], segment);
// isBitSet will be true if given bit is 1
digitalWrite(segmentPins[segment], isBitSet);
digitalWrite(segmentPins[0], HIGH);
}
}