From 74b45e98fb536b6e69979fde2af191fa9c024e6c Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Mon, 29 Sep 2014 23:50:08 +0300 Subject: Add reset button led direction flip --- hello.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 24 deletions(-) (limited to 'hello.c') diff --git a/hello.c b/hello.c index e475624..5388dbd 100644 --- a/hello.c +++ b/hello.c @@ -1,35 +1,68 @@ +#include #include #include -int -main (void) -{ +uint8_t state; + + +int main() { + state = eeprom_read_byte((uint8_t*)0) & 1; + if ((MCUSR & (1 << PORF)) != 0) { + MCUSR = 1; + state ^= 1; + eeprom_write_byte((uint8_t*)0, state); + } + DDRB |= _BV(DDB0); DDRB |= _BV(DDB1); DDRB |= _BV(DDB2); DDRB |= _BV(DDB3); DDRB |= _BV(DDB4); - while(1) { - PORTB ^= _BV(PB0); - _delay_ms(500); - PORTB ^= _BV(PB0); - - PORTB ^= _BV(PB1); - _delay_ms(500); - PORTB ^= _BV(PB1); - - PORTB ^= _BV(PB2); - _delay_ms(500); - PORTB ^= _BV(PB2); - - PORTB ^= _BV(PB3); - _delay_ms(500); - PORTB ^= _BV(PB3); - - PORTB ^= _BV(PB4); - _delay_ms(500); - PORTB ^= _BV(PB4); - } + + while (1) { + if (state == 1) { + PORTB ^= _BV(PB4); + _delay_ms(500); + PORTB ^= _BV(PB4); + + PORTB ^= _BV(PB3); + _delay_ms(500); + PORTB ^= _BV(PB3); + + PORTB ^= _BV(PB2); + _delay_ms(500); + PORTB ^= _BV(PB2); + + PORTB ^= _BV(PB1); + _delay_ms(500); + PORTB ^= _BV(PB1); + + PORTB ^= _BV(PB0); + _delay_ms(500); + PORTB ^= _BV(PB0); + } + else { + PORTB ^= _BV(PB0); + _delay_ms(500); + PORTB ^= _BV(PB0); + + PORTB ^= _BV(PB1); + _delay_ms(500); + PORTB ^= _BV(PB1); + + PORTB ^= _BV(PB2); + _delay_ms(500); + PORTB ^= _BV(PB2); + + PORTB ^= _BV(PB3); + _delay_ms(500); + PORTB ^= _BV(PB3); + + PORTB ^= _BV(PB4); + _delay_ms(500); + PORTB ^= _BV(PB4); + } + } } -- cgit v1.3.1