// 7 Segment LED /* 6 5 0 1 G F g A B 10 9 8 7 6 A F B G E C D 1 2 3 4 5 E D g C dp 4 3 2 */ #define pA 0 /* segment A goes to pin 0 */ #define pB 1 /* segment B goes to pin 1 */ #define pC 2 /* segment C goes to pin 2 */ #define pD 3 /* segment D goes to pin 3 */ #define pE 4 /* segment E goes to pin 4 */ #define pF 5 /* segment F goes to pin 5 */ #define pG 6 /* segment G goes to pin 6 */ #define pDP 0 /* no connect -- not using */ int digits[10][7] = { /* which pins should be on for each digit */ /* A B C D E F G */ {1, 1, 1, 1, 1, 1, 0}, /* 0 */ {0, 1, 1, 0, 0, 0, 0}, /* 1 */ {1, 1, 0, 1, 1, 0, 1}, /* 2 */ {1, 1, 1, 1, 0, 0, 1}, /* 3 */ {0, 1, 1, 0, 0, 1, 1}, /* 4 */ {1, 0, 1, 1, 0, 1, 1}, /* 5 */ {1, 0, 1, 1, 1, 1, 1}, /* 6 */ {1, 1, 1, 0, 0, 0, 0}, /* 7 */ {1, 1, 1, 1, 1, 1, 1}, /* 8 */ {1, 1, 1, 1, 0, 1, 1} /* 9 */ }; /* which pins should be on for each digit */ int dlay; void setup() { dlay = 100; pinMode(pA,OUTPUT); pinMode(pB,OUTPUT); pinMode(pC,OUTPUT); pinMode(pD,OUTPUT); pinMode(pE,OUTPUT); pinMode(pF,OUTPUT); pinMode(pG,OUTPUT); } void loop() { int i; for (i=0; 10>i; i++) { /* for */ displayDigit(i); delay(dlay); } /* for */ for (i=9; 0<=i; i--) { /* for */ displayDigit(i); delay(dlay); } /* for */ } void displayDigit(int d) { /* FUNCTION digit */ int i; for (i=0; 7>i; i++) { /* for */ digitalWrite(i, digits[d][i]); }/* for */ } /* FUNCTION digit */