add reset button
This commit is contained in:
parent
3560c225a4
commit
bb17abaa90
24
main.c
24
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue