add reset button

This commit is contained in:
Lea 2023-08-29 19:11:48 +02:00
parent 3560c225a4
commit bb17abaa90
Signed by: Lea
GPG key ID: 1BAFFE8347019C42

24
main.c
View file

@ -12,6 +12,7 @@
int timer_start = 0xffff - (F_CPU / 1024 / 1000); int timer_start = 0xffff - (F_CPU / 1024 / 1000);
volatile uint32_t ticks = 0; volatile uint32_t ticks = 0;
volatile bool counting = false;
void start_timer() { void start_timer() {
// Sets the Clock Select. See table on page 157 the Atmel datasheet. // 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. // is triggered whenever timer 1 (16 bit) overflows.
ISR(TIMER1_OVF_vect) { ISR(TIMER1_OVF_vect) {
TCNT1 = timer_start; // TODO figure out how to get the correct number TCNT1 = timer_start; // TODO figure out how to get the correct number
ticks += 1; if (counting) ticks += 1;
} }
void prog_7segment() { void prog_7segment() {
@ -69,26 +70,25 @@ void prog_7segment() {
void prog_7segment_4digit() { void prog_7segment_4digit() {
DDRF = 0b11111111; DDRF = 0b11111111;
DDRK = 0b00001111; DDRK = 0b00001111;
PORTK = 0b10000000; // set pull-up PORTK = 0b11000000; // set pull-up
float num = 0.0f; float num = 0.0f;
bool running = false; bool pressed_pause = false;
bool pressed = false;
while(1) { while(1) {
show_float(ticks / 1000.0f); show_float(ticks / 1000.0f);
float sleep_time = update_display(); float sleep_time = update_display();
if (!pressed && bit_is_clear(PINK, PINK7)) { if (!pressed_pause && bit_is_clear(PINK, PINK7)) {
running = !running; counting = !counting;
pressed = true; pressed_pause = true;
} else if (pressed && bit_is_set(PINK, PINK7)) { } else if (pressed_pause && bit_is_set(PINK, PINK7)) {
pressed = false; pressed_pause = false;
} }
if (running) { if (bit_is_clear(PINK, PINK6)) {
num += sleep_time / 1000.0f / 1000.0f; ticks = 0;
if (num >= 10000) num = 0.0f; counting = false;
} }
} }
} }