Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // HIGH and LOW are aliases for 1 and 0 respectively
- // each of these uses only 1 byte of memory
- const unsigned char digit_bits[] = {
- 0b11111100, // 0
- 0b01100000, // 1
- 0b11011010, // 2
- 0b11110010, // 3
- 0b01100110, // 4
- 0b10110110, // 5
- 0b10111110, // 6
- 0b11100000, // 7
- 0b11111110, // 8
- 0b11110110 // 9
- // you could have bit patterns for other digits after this, such as hexadecimal
- };
- void display_digit( int which_digit, int number ) {
- unsigned char bits;
- digitalWrite( which_digit, HIGH );
- bits = ~digit_bits[ number ];
- // flip all the bits, since 0 means the segment is on apparently
- // this could also overrun the array and show garbage, but that's the fun part
- // write the bits out backwards, so that the definitions are more readable
- digitalWrite( SEG_DOT, bits & 1 ); bits >>= 1;
- digitalWrite( SEG_G, bits & 1 ); bits >>= 1;
- digitalWrite( SEG_F, bits & 1 ); bits >>= 1;
- digitalWrite( SEG_E, bits & 1 ); bits >>= 1;
- digitalWrite( SEG_D, bits & 1 ); bits >>= 1;
- digitalWrite( SEG_C, bits & 1 ); bits >>= 1;
- digitalWrite( SEG_B, bits & 1 ); bits >>= 1;
- digitalWrite( SEG_A, bits );
- delay( GHOST_DELAY );
- digitalWrite( which_digit, LOW );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement