fix counter

This commit is contained in:
Lea 2023-08-29 09:53:00 +02:00
parent 479d0f6df0
commit e393c10801
Signed by: Lea
GPG key ID: 1BAFFE8347019C42
3 changed files with 23 additions and 8 deletions

View file

@ -28,11 +28,14 @@ void set_display_value(uint8_t digit, uint8_t data) {
display[digit] = data;
}
void update_display() {
// Returns the amount of microseconds we blocked for
float update_display() {
int sleep_time = 2000;
for (int i = 0; i < 4; i++) {
display_value(i, display[i]);
_delay_us(100);
_delay_us(sleep_time);
}
return sleep_time * 4;
}
void show_float(float value) {

View file

@ -4,6 +4,6 @@ void display_value(uint8_t digit, uint8_t data);
void set_display_value(uint8_t digit, uint8_t data);
void update_display();
float update_display();
void show_float(float value);

22
main.c
View file

@ -40,16 +40,28 @@ void prog_7segment() {
}
void prog_7segment_4digit() {
DDRF = 0b11111111;
DDRK = 0b00001111;
DDRF = 0b11111111;
DDRK = 0b00001111;
PORTK = 0b10000000; // set pull-up
float num = 0.0f;
bool running = false;
bool pressed = false;
while(1) {
show_float(num);
update_display();
float sleep_time = update_display();
num += 0.001f;
if (num >= 10000) num = 0.0f;
if (!pressed && bit_is_clear(PINK, PINK7)) {
running = !running;
pressed = true;
} else if (pressed && bit_is_set(PINK, PINK7)) {
pressed = false;
}
if (running) {
num += sleep_time / 1000.0f / 1000.0f;
if (num >= 10000) num = 0.0f;
}
}
}