From bb17abaa908c1e8d919bef837822a96643cfd43e Mon Sep 17 00:00:00 2001 From: Lea Date: Tue, 29 Aug 2023 19:11:48 +0200 Subject: [PATCH] add reset button --- main.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/main.c b/main.c index 154713a..6ef26d9 100644 --- a/main.c +++ b/main.c @@ -12,6 +12,7 @@ int timer_start = 0xffff - (F_CPU / 1024 / 1000); volatile uint32_t ticks = 0; +volatile bool counting = false; void start_timer() { // Sets the Clock Select. See table on page 157 the Atmel datasheet. @@ -37,7 +38,7 @@ void main() { // is triggered whenever timer 1 (16 bit) overflows. ISR(TIMER1_OVF_vect) { TCNT1 = timer_start; // TODO figure out how to get the correct number - ticks += 1; + if (counting) ticks += 1; } void prog_7segment() { @@ -69,26 +70,25 @@ void prog_7segment() { void prog_7segment_4digit() { DDRF = 0b11111111; DDRK = 0b00001111; - PORTK = 0b10000000; // set pull-up + PORTK = 0b11000000; // set pull-up float num = 0.0f; - bool running = false; - bool pressed = false; + bool pressed_pause = false; while(1) { show_float(ticks / 1000.0f); float sleep_time = update_display(); - if (!pressed && bit_is_clear(PINK, PINK7)) { - running = !running; - pressed = true; - } else if (pressed && bit_is_set(PINK, PINK7)) { - pressed = false; + if (!pressed_pause && bit_is_clear(PINK, PINK7)) { + counting = !counting; + pressed_pause = true; + } else if (pressed_pause && bit_is_set(PINK, PINK7)) { + pressed_pause = false; } - if (running) { - num += sleep_time / 1000.0f / 1000.0f; - if (num >= 10000) num = 0.0f; + if (bit_is_clear(PINK, PINK6)) { + ticks = 0; + counting = false; } } }