random blue
This commit is contained in:
parent
fac40519dc
commit
bb993a6366
1
led.c
1
led.c
@ -20,6 +20,7 @@ tColor matrix[SIZE][SIZE] = {
|
||||
{ OFF, OFF, OFF, OFF }
|
||||
};
|
||||
|
||||
|
||||
void ledSetMatrix(uint8_t col, uint8_t row, tColor color) {
|
||||
if ((col < SIZE) && (row < SIZE)) {
|
||||
matrix[col][row] = color;
|
||||
|
1
led.h
1
led.h
@ -19,5 +19,4 @@ void ledInit();
|
||||
void ledExec();
|
||||
void ledSetMatrix(uint8_t col, uint8_t row, tColor color);
|
||||
|
||||
|
||||
#endif /* LED_H_ */
|
||||
|
44
pattern.c
44
pattern.c
@ -4,7 +4,8 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* traversing the whole matrix
|
||||
void patternExec() {
|
||||
static uint8_t i = 0;
|
||||
static uint8_t j = 0;
|
||||
@ -21,7 +22,48 @@ void patternExec() {
|
||||
}
|
||||
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() {
|
||||
schAdd(patternExec, NULL, 0, 500);
|
||||
|
Loading…
x
Reference in New Issue
Block a user