From 551b210656918cc3ab05f5c4ff5ec4873c268fe1 Mon Sep 17 00:00:00 2001 From: Eggert Jung Date: Mon, 27 Dec 2021 03:08:09 +0100 Subject: [PATCH] clean up code --- code/src/main.c | 95 +++++++++++++-------------------------------------------- 1 file changed, 21 insertions(+), 74 deletions(-) diff --git a/code/src/main.c b/code/src/main.c index 6e8f577..2224299 100644 --- a/code/src/main.c +++ b/code/src/main.c @@ -4,35 +4,24 @@ #include #include +// 1 count = 0,065536 s +#define ACTIVE_COUNT_MAX 13733 +#define ANIMATION_INTERVALL 3 + uint8_t EEMEM on_off_state; +volatile uint32_t leds = 0x00; uint8_t anim_nr = 0; -unsigned long NextVal(void); -unsigned long InitSeed(void); void random(void); void links_rechts(void); +void (*animation[])(void) = { + links_rechts, + random +}; -void (*animation[4])(void); - -volatile uint32_t leds = 0x00; - -volatile uint32_t active_count = 0; -volatile uint32_t active_count_max = 13733; // 1 count = 0,065536 s - -volatile uint16_t count = 0; -volatile uint16_t count_max = 3; - -volatile uint8_t dir = 0; - -static unsigned long Seed; - -unsigned long InitSeed() -{ - return NextVal(); -} - -unsigned long NextVal() +unsigned long NextVal(void) { + static unsigned long Seed; Seed=Seed*1632125L+1013904223L; return Seed; } @@ -47,6 +36,7 @@ void random(){ } void links_rechts(){ + static uint8_t dir = 0; if(dir) leds = leds << 1; else @@ -66,9 +56,6 @@ void write_leds(void){ int main(void) { - animation[0] = links_rechts; - animation[1] = random; - // reset switch as on/off switch if(eeprom_read_byte(&on_off_state)){ eeprom_write_byte(&on_off_state, 0); @@ -80,34 +67,24 @@ int main(void) // power consumption is below 1uA } - InitSeed(); DDRC = 0xFF; DDRD = 0xFF; DDRB = 0x07; - //DDRB &= ~(1 << DDB0); // Clear the PB0, PB1, PB2 pin - // PB0,PB1,PB2 (PCINT0, PCINT1, PCINT2 pin) are now inputs - - //PORTB |= ((1 << PORTB0) | (1 << PORTB1) | (1 << PORTB2)); // turn On the Pull-up - // PB0, PB1 and PB2 are now inputs with pull-up enabled - - //TIMSK1 |= 1 << TOIE1; - TCCR0B |= (1<=count_max){ + if(count>=ANIMATION_INTERVALL){ count=0; (*animation[anim_nr])(); } @@ -150,23 +111,9 @@ ISR(TIMER0_OVF_vect){ { count++; } - if(active_count >= active_count_max){ + if(active_count >= ACTIVE_COUNT_MAX){ active_count=0; //leds_active = 0; //TODO maybe sleep here } } - -//ISR(TIMER1_OVF_vect){ -// if(debounce_count >= debounce_count_max) -// { -// TCCR1B &= ~(1<