#include "pattern.h" #include "led.h" #include "PontCoopScheduler.h" #include #include "myrand.h" /* * traversing the whole matrix void patternExec() { static uint8_t i = 0; static uint8_t j = 0; ledSetMatrix(i, j, OFF); i++; if (i > 3) { i = 0; j++; if (j > 3) { j = 0; } } ledSetMatrix(i, j, BLUE); } */ /* * 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); srand(13); 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; break; default: state = 0; break; } } */ void patternExec() { static uint8_t state = 0; static uint8_t column = 0; static uint8_t stay = 0; switch (state) { case 0: // initialize ledSetMatrix(0, 3, RED); ledSetMatrix(1, 3, RED); ledSetMatrix(2, 3, RED); ledSetMatrix(3, 3, RED); srand(13); state = 1; break; case 1: // select new column, row 2 column = myrand() & 0x3; ledSetMatrix(column, 2, RED); stay = myrand() & 0xf; state = 2; break; case 2: // stay if (stay == 0) { state = 3; } stay--; break; case 3: // same column, row 1 ledSetMatrix(column, 1, RED); ledSetMatrix(column, 2, OFF); stay = myrand() & 0xf; state = 4; break; case 4: // stay if (stay == 0) { state = 5; } stay--; break; case 5: // same column, row 0 ledSetMatrix(column, 0, RED); ledSetMatrix(column, 1, OFF); stay = myrand() & 0xf; state = 6; break; case 6: // stay if (stay == 0) { state = 7; } stay--; break; case 7: // same column, row 0 off ledSetMatrix(column, 0, OFF); state = 1; break; default: state = 0; break; } } void patternInit() { schAdd(patternExec, NULL, 0, 100); }