diff --git a/led.c b/led.c index 5c328e9..78e4ad0 100644 --- a/led.c +++ b/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; diff --git a/led.h b/led.h index 72c9a98..7bb712a 100644 --- a/led.h +++ b/led.h @@ -19,5 +19,4 @@ void ledInit(); void ledExec(); void ledSetMatrix(uint8_t col, uint8_t row, tColor color); - #endif /* LED_H_ */ diff --git a/pattern.c b/pattern.c index d0ba4bb..0d6b289 100644 --- a/pattern.c +++ b/pattern.c @@ -4,7 +4,8 @@ #include - +/* + * 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);