/* 7 Segment LED This example code is in the public domain. */ // we will use pins 0-6 to be the 7 pins of the display (ignore decimal point) // 7 segment LED // a // f b // g // e c // d // 0 is a b c d e f 1111110 // 1 is b c 0110000 // 2 is a b d e g 1101101 // 3 is a b c d g 1111001 // 4 is b c f g 0110011 // 5 is a c d f g 1011011 // 6 is a c d e f g 1011111 // 7 is a b c 1110000 // 8 is a b c d e f g 1111111 // 9 is a b c d f g 1111011 int digits[10] = { 0b1111110, 0b0110000, 0b1101101, 0b1111001, 0b0110011, 0b1011011, 0b1011111, 0b1110000, 0b1111111, 0b1111011 }; int bits[7] = { 0b0000001, 0b0000010, 0b0000100, 0b0001000, 0b0010000, 0b0100000, 0b1000000 }; // the setup routine runs once when you press reset: void setup() { int i; // initialize the digital output pins for (i=0; i<7; i++) { /* for each segment/pin */ pinMode(i, OUTPUT); } /* for each segment/pin */ } // the loop routine runs over and over again forever: void loop() { int i; for (i=0; i<10; i++) { /* for */ displayDigit(i); delay(1000); } /* for */ } void displayDigit(int d) { /* FUNCTION displayDigit */ int i; for (i=0; i<7; i++) { /* for */ if (bitSet(i,d)) digitalWrite(i, HIGH); else digitalWrite(i, LOW); } /* for */ } /* FUNCTION displayDigit */ int birSet(int b, int d) { /* FUNCTION bitSet */ int tmp; tmp = bits[b] == (bits[b] & d); return tmp; } /* FUNCTION bitSet */