diff options
| author | Akshay Nair <phenax5@gmail.com> | 2026-02-01 22:30:52 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2026-02-02 11:12:55 +0530 |
| commit | ef92c7d564c2d99b15ada6b9b48cd452230ad022 (patch) | |
| tree | 05bd3dd75e0a2bd50af2c6cc158399ed9dfa758d | |
| parent | 8fa32bb0414c3164d8c3467c5db4c1a912627fc4 (diff) | |
| download | daft-watch-ef92c7d564c2d99b15ada6b9b48cd452230ad022.tar.gz daft-watch-ef92c7d564c2d99b15ada6b9b48cd452230ad022.zip | |
Finished counter + digit display
| -rw-r--r-- | .gitignore | 5 | ||||
| -rw-r--r-- | src/main.c | 43 |
2 files changed, 11 insertions, 37 deletions
@@ -1,9 +1,4 @@ -.pio .clang_complete -.gcc-flags.json .ccls -.cache/ -compile_commands.json -compiler_defines.h a.out out/ @@ -1,50 +1,29 @@ #include <avr/io.h> #include <util/delay.h> -// gfedcba +// a b c d e f g decimal +// Reversed because a-g is mapped to pa0-6. (pa7 is decimal) +// Complemented because display is common anode const long digits[] = { - 0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110, - 0b1101101, 0b1111101, 0b0000111, 0b1111111, 0b1101111, + 0b01000000, 0b01111001, 0b00100100, 0b00110000, 0b00011001, + 0b00010010, 0b00000010, 0b01111000, 0b00000000, 0b00010000, }; -// a, b, c, d, e, f, g -const int segment_pins[] = {4, 5, 6, 7, 8, 9, 10}; - void write_digit(int digit) { if (digit > 9 || digit < 0) return; - long mask = digits[digit]; - for (int i = 0; i < 7; i++) { - short on = 0 != (mask & (i == 0 ? 1 : 2 << (i - 1))); - // digitalWrite(segment_pins[i], on); - } -} - -void setup(void) { - for (int i = 0; i < 7; i++) { - int pin = segment_pins[i]; - DDRA |= (1 << PA1); - } -} - -int i = 0; -void loop(void) { - write_digit(i); - _delay_ms(500); - i = (i + 1) % 10; + PORTA = digits[digit]; } int main(void) { - setup(); + DDRA |= 0b11111111; + int i = 0; while (1) { - loop(); - // PORTA |= (1 << PA1); - // _delay_ms(500); - // PORTA &= ~(1 << PA1); - // _delay_ms(500); + write_digit(i); + _delay_ms(500); + i = (i + 1) % 10; } - return 0; } |
