diff --git a/firmware/apps/blinker.c b/firmware/apps/blinker.c index 78f7e49..fc45329 100644 --- a/firmware/apps/blinker.c +++ b/firmware/apps/blinker.c @@ -11,18 +11,16 @@ static void blinker(void) { led_inv(RIGHT); led_inv(LEFT); - uint8_t i; - for(i = 0; i < 50; ++i) { - if(button_clicked(RIGHT)) { - motor_on(); - } + wait_ms(500); - if(button_clicked(LEFT)) { - motor_off(); - } - - wait_ms(10); + if(button_clicked(RIGHT)) { + motor_on(); } + + if(button_clicked(LEFT)) { + motor_off(); + } + } REGISTER(blinker, init, NULL); diff --git a/firmware/doc/befehle.odt b/firmware/doc/befehle.odt new file mode 100644 index 0000000..3ebda3b Binary files /dev/null and b/firmware/doc/befehle.odt differ diff --git a/firmware/include/pentabug/matrix.h b/firmware/include/pentabug/matrix.h new file mode 100644 index 0000000..a4fd56d --- /dev/null +++ b/firmware/include/pentabug/matrix.h @@ -0,0 +1,14 @@ +#ifndef MATRIX_H +#define MATRIX_H + +#include + +void matrix_start(void); +void matrix_stop(void); + +void matrix_show(void); +void matrix_init(void); + +void matrix_set(uint8_t x, uint8_t y, uint8_t active); + +#endif /* MATRIX_H */ diff --git a/firmware/lib/matrix.c b/firmware/lib/matrix.c new file mode 100644 index 0000000..35826c8 --- /dev/null +++ b/firmware/lib/matrix.c @@ -0,0 +1,70 @@ +#include + +#include +#include + +static uint8_t pixels[9]; +static uint8_t index; + +void matrix_init(void) { + DDRD |= (1 << 5) | (1 << 6) | (1 << 7); + DDRC |= (1 << 4) | (1 << 5); + DDRB |= 1 << 2; +} + +static void move_line(uint8_t line) { + PORTD &= ~0xe0; + PORTD |= 1 << (line + 5); +} + +static void write_line(uint8_t data[]) { + PORTC |= (1 << 5) | (1 << 4); + PORTB |= 1 << 2; + + if(data[0]) { + PORTC &= ~(1 << 5); + } + + if(data[1]) { + PORTC &= ~(1 << 4); + } + + if(data[2]) { + PORTB &= ~(1 << 2); + } +} + +static void matrix_int(void) { + ++index; + + if(index >= 3) { + index = 0; + } + + move_line(index); + write_line(pixels + (index * 3)); +} + +void matrix_start(void) { + matrix_init(); + start_timer(PRESCALE_64, 125, matrix_int); +} + +void matrix_stop(void) { + stop_timer(); +} + +void matrix_show(void) { + uint8_t i; + + for(i = 0; i < 3; ++i) { + move_line(i); + write_line(pixels + (i * 3)); + wait_ms(3); + } +} + +void matrix_set(uint8_t x, uint8_t y, uint8_t active) { + pixels[x*3+y] = active; +} +