aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c50
-rw-r--r--src/main.cpp16
2 files changed, 50 insertions, 16 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..a7e2646
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,50 @@
+#include <avr/io.h>
+#include <util/delay.h>
+
+// gfedcba
+const long digits[] = {
+ 0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110,
+ 0b1101101, 0b1111101, 0b0000111, 0b1111111, 0b1101111,
+};
+
+// 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;
+}
+
+int main(void) {
+ setup();
+
+ while (1) {
+ loop();
+ // PORTA |= (1 << PA1);
+ // _delay_ms(500);
+ // PORTA &= ~(1 << PA1);
+ // _delay_ms(500);
+ }
+
+ return 0;
+}
diff --git a/src/main.cpp b/src/main.cpp
deleted file mode 100644
index 6226244..0000000
--- a/src/main.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <Arduino.h>
-
-// Physical Pin 2 on the ATtiny84a is Arduino Digital Pin 0
-#define LED_PIN 0
-
-void setup() {
- // Initialize the digital pin as an output.
- pinMode(LED_PIN, OUTPUT);
-}
-
-void loop() {
- digitalWrite(LED_PIN, HIGH); // Turn the LED on
- delay(1000); // Wait for a second
- digitalWrite(LED_PIN, LOW); // Turn the LED off
- delay(1000); // Wait for a second
-}