Fix draw() function to actually draw whole bitmap.
This commit is contained in:
parent
c7372a278d
commit
ca4b2e5e31
@ -38,45 +38,42 @@ static void init(void) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw(uint8_t buffer[4][4]) {
|
void draw(uint8_t buffer[4][4], uint8_t delay) {
|
||||||
static uint8_t row = 0;
|
|
||||||
|
|
||||||
/* Turn off whole row. */
|
for (uint8_t row=0; row<4; ++row) {
|
||||||
digital_write(row_pins[row], HIGH);
|
/* Connect or disconnect columns as needed. */
|
||||||
|
for (uint8_t column=0; column<4; ++column) {
|
||||||
|
digital_write(column_pins[column], buffer[row][column]);
|
||||||
|
}
|
||||||
|
|
||||||
/* Advance one row and make sure it is 0..4 */
|
/* Turn on whole row. */
|
||||||
row++;
|
digital_write(row_pins[row], LOW);
|
||||||
row = row % 4;
|
|
||||||
|
|
||||||
/* Connect or disconnect columns as needed. */
|
_delay_ms(delay);
|
||||||
for (uint8_t column=0; column<4; column++) {
|
|
||||||
digital_write(column_pins[column], buffer[row][column]);
|
/* 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();
|
init();
|
||||||
|
|
||||||
/* With 100ms delay eye can see updating row by row. */
|
/* With 100ms delay eye can see updating row by row. */
|
||||||
for (uint8_t i=0; i<40; i++) {
|
for (uint8_t i=0; i<10; i++) {
|
||||||
draw(pattern);
|
draw(pattern, 100);
|
||||||
_delay_ms(100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* With 10ms delay pattern appears but flickers. */
|
/* With 10ms delay pattern appears but flickers. */
|
||||||
for (uint16_t i=0; i<400; i++) {
|
for (uint16_t i=0; i<100; i++) {
|
||||||
draw(pattern);
|
draw(pattern, 10);
|
||||||
_delay_ms(10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Withoud delay solid pattern appears. */
|
/* Withoud delay solid pattern appears. */
|
||||||
while (1) {
|
while (1) {
|
||||||
draw(pattern);
|
draw(pattern, 1);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
static void init(void);
|
static void init(void);
|
||||||
void draw(uint8_t buffer[4][4]);
|
void draw(uint8_t buffer[4][4], uint8_t delay);
|
||||||
int main(void);
|
uint8_t main(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user