random blue

This commit is contained in:
Wolfgang Hottgenroth 2019-02-03 22:34:29 +01:00
parent fac40519dc
commit bb993a6366
Signed by: wn
GPG Key ID: B586EAFCDF2F65F4
3 changed files with 44 additions and 2 deletions

1
led.c
View File

@ -20,6 +20,7 @@ tColor matrix[SIZE][SIZE] = {
{ OFF, OFF, OFF, OFF } { OFF, OFF, OFF, OFF }
}; };
void ledSetMatrix(uint8_t col, uint8_t row, tColor color) { void ledSetMatrix(uint8_t col, uint8_t row, tColor color) {
if ((col < SIZE) && (row < SIZE)) { if ((col < SIZE) && (row < SIZE)) {
matrix[col][row] = color; matrix[col][row] = color;

1
led.h
View File

@ -19,5 +19,4 @@ void ledInit();
void ledExec(); void ledExec();
void ledSetMatrix(uint8_t col, uint8_t row, tColor color); void ledSetMatrix(uint8_t col, uint8_t row, tColor color);
#endif /* LED_H_ */ #endif /* LED_H_ */

View File

@ -4,7 +4,8 @@
#include <stdlib.h> #include <stdlib.h>
/*
* traversing the whole matrix
void patternExec() { void patternExec() {
static uint8_t i = 0; static uint8_t i = 0;
static uint8_t j = 0; static uint8_t j = 0;
@ -21,7 +22,48 @@ void patternExec() {
} }
ledSetMatrix(i, j, BLUE); ledSetMatrix(i, j, BLUE);
} }
*/
void patternExec() {
static uint8_t state = 0;
static uint8_t column = 0;
switch (state) {
case 0:
// initialize
ledSetMatrix(0, 0, BLUE);
ledSetMatrix(1, 0, BLUE);
ledSetMatrix(2, 0, BLUE);
ledSetMatrix(3, 0, BLUE);
state = 1;
break;
case 1:
// select new column, row 1
column = ((uint8_t) rand()) & 0x3;
ledSetMatrix(column, 1, BLUE);
state = 2;
break;
case 2:
// same column, row 2
ledSetMatrix(column, 2, BLUE);
ledSetMatrix(column, 1, OFF);
state = 3;
break;
case 3:
// same column, row 3
ledSetMatrix(column, 3, BLUE);
ledSetMatrix(column, 2, OFF);
state = 4;
break;
case 4:
// same column, row 3 off
ledSetMatrix(column, 3, OFF);
state = 1;
default:
state = 0;
break;
}
}
void patternInit() { void patternInit() {
schAdd(patternExec, NULL, 0, 500); schAdd(patternExec, NULL, 0, 500);