From ca4b2e5e317118977776b12b2462f25c7c571916 Mon Sep 17 00:00:00 2001 From: Mika Tuupola Date: Fri, 4 Nov 2011 01:20:23 +0200 Subject: [PATCH] Fix draw() function to actually draw whole bitmap. --- 4x4_matrix_part_1/main.c | 45 +++++++++++++++++++--------------------- 4x4_matrix_part_1/main.h | 4 ++-- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/4x4_matrix_part_1/main.c b/4x4_matrix_part_1/main.c index a12b98b..e8488dc 100644 --- a/4x4_matrix_part_1/main.c +++ b/4x4_matrix_part_1/main.c @@ -38,45 +38,42 @@ static void init(void) { } -void draw(uint8_t buffer[4][4]) { - static uint8_t row = 0; +void draw(uint8_t buffer[4][4], uint8_t delay) { + + for (uint8_t row=0; row<4; ++row) { + /* Connect or disconnect columns as needed. */ + for (uint8_t column=0; column<4; ++column) { + digital_write(column_pins[column], buffer[row][column]); + } + + /* Turn on whole row. */ + digital_write(row_pins[row], LOW); - /* Turn off whole row. */ - digital_write(row_pins[row], HIGH); - - /* Advance one row and make sure it is 0..4 */ - row++; - row = row % 4; - - /* Connect or disconnect columns as needed. */ - for (uint8_t column=0; column<4; column++) { - digital_write(column_pins[column], buffer[row][column]); + _delay_ms(delay); + + /* Turn off whole row. */ + digital_write(row_pins[row], HIGH); } - - /* Turn on whole row. */ - digital_write(row_pins[row], LOW); } -int main(void) { +uint8_t main(void) { init(); /* With 100ms delay eye can see updating row by row. */ - for (uint8_t i=0; i<40; i++) { - draw(pattern); - _delay_ms(100); + for (uint8_t i=0; i<10; i++) { + draw(pattern, 100); } /* With 10ms delay pattern appears but flickers. */ - for (uint16_t i=0; i<400; i++) { - draw(pattern); - _delay_ms(10); + for (uint16_t i=0; i<100; i++) { + draw(pattern, 10); } /* Withoud delay solid pattern appears. */ while (1) { - draw(pattern); + draw(pattern, 1); } + return 0; - } diff --git a/4x4_matrix_part_1/main.h b/4x4_matrix_part_1/main.h index ee7f6e8..f122f89 100644 --- a/4x4_matrix_part_1/main.h +++ b/4x4_matrix_part_1/main.h @@ -1,3 +1,3 @@ static void init(void); -void draw(uint8_t buffer[4][4]); -int main(void); +void draw(uint8_t buffer[4][4], uint8_t delay); +uint8_t main(void);