2019-02-02 16:54:24 +01:00
|
|
|
#include "pattern.h"
|
|
|
|
#include "led.h"
|
|
|
|
#include "PontCoopScheduler.h"
|
|
|
|
#include <stdlib.h>
|
2019-02-03 23:19:09 +01:00
|
|
|
#include "myrand.h"
|
2019-02-02 16:54:24 +01:00
|
|
|
|
2019-02-03 22:34:29 +01:00
|
|
|
/*
|
|
|
|
* traversing the whole matrix
|
2019-02-02 16:54:24 +01:00
|
|
|
void patternExec() {
|
|
|
|
static uint8_t i = 0;
|
|
|
|
static uint8_t j = 0;
|
|
|
|
|
2019-02-02 18:03:04 +01:00
|
|
|
ledSetMatrix(i, j, OFF);
|
2019-02-02 16:54:24 +01:00
|
|
|
|
|
|
|
i++;
|
|
|
|
if (i > 3) {
|
|
|
|
i = 0;
|
|
|
|
j++;
|
|
|
|
if (j > 3) {
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
}
|
2019-02-02 18:03:04 +01:00
|
|
|
ledSetMatrix(i, j, BLUE);
|
2019-02-02 16:54:24 +01:00
|
|
|
}
|
2019-02-03 22:34:29 +01:00
|
|
|
*/
|
|
|
|
|
2019-02-03 22:52:25 +01:00
|
|
|
/*
|
|
|
|
* BLUE
|
2019-02-03 22:34:29 +01:00
|
|
|
void patternExec() {
|
|
|
|
static uint8_t state = 0;
|
|
|
|
static uint8_t column = 0;
|
2019-02-02 16:54:24 +01:00
|
|
|
|
2019-02-03 22:34:29 +01:00
|
|
|
switch (state) {
|
|
|
|
case 0:
|
|
|
|
// initialize
|
|
|
|
ledSetMatrix(0, 0, BLUE);
|
|
|
|
ledSetMatrix(1, 0, BLUE);
|
|
|
|
ledSetMatrix(2, 0, BLUE);
|
|
|
|
ledSetMatrix(3, 0, BLUE);
|
2019-02-03 22:52:25 +01:00
|
|
|
srand(13);
|
2019-02-03 22:34:29 +01:00
|
|
|
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;
|
2019-02-03 22:52:25 +01:00
|
|
|
break;
|
2019-02-03 22:34:29 +01:00
|
|
|
default:
|
|
|
|
state = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-02-03 22:52:25 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
void patternExec() {
|
|
|
|
static uint8_t state = 0;
|
|
|
|
static uint8_t column = 0;
|
2019-02-03 23:19:09 +01:00
|
|
|
static uint8_t stay = 0;
|
2019-02-03 22:52:25 +01:00
|
|
|
|
|
|
|
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
|
2019-02-03 23:19:09 +01:00
|
|
|
column = myrand() & 0x3;
|
2019-02-03 22:52:25 +01:00
|
|
|
ledSetMatrix(column, 2, RED);
|
2019-02-03 23:19:09 +01:00
|
|
|
stay = myrand() & 0xf;
|
2019-02-03 22:52:25 +01:00
|
|
|
state = 2;
|
|
|
|
break;
|
|
|
|
case 2:
|
2019-02-03 23:19:09 +01:00
|
|
|
// stay
|
|
|
|
if (stay == 0) {
|
|
|
|
state = 3;
|
|
|
|
}
|
|
|
|
stay--;
|
|
|
|
break;
|
|
|
|
case 3:
|
2019-02-03 22:52:25 +01:00
|
|
|
// same column, row 1
|
|
|
|
ledSetMatrix(column, 1, RED);
|
|
|
|
ledSetMatrix(column, 2, OFF);
|
2019-02-03 23:19:09 +01:00
|
|
|
stay = myrand() & 0xf;
|
|
|
|
state = 4;
|
2019-02-03 22:52:25 +01:00
|
|
|
break;
|
2019-02-03 23:19:09 +01:00
|
|
|
case 4:
|
|
|
|
// stay
|
|
|
|
if (stay == 0) {
|
|
|
|
state = 5;
|
|
|
|
}
|
|
|
|
stay--;
|
|
|
|
break;
|
|
|
|
case 5:
|
2019-02-03 22:52:25 +01:00
|
|
|
// same column, row 0
|
|
|
|
ledSetMatrix(column, 0, RED);
|
|
|
|
ledSetMatrix(column, 1, OFF);
|
2019-02-03 23:19:09 +01:00
|
|
|
stay = myrand() & 0xf;
|
|
|
|
state = 6;
|
2019-02-03 22:52:25 +01:00
|
|
|
break;
|
2019-02-03 23:19:09 +01:00
|
|
|
case 6:
|
|
|
|
// stay
|
|
|
|
if (stay == 0) {
|
|
|
|
state = 7;
|
|
|
|
}
|
|
|
|
stay--;
|
|
|
|
break;
|
|
|
|
case 7:
|
2019-02-03 22:52:25 +01:00
|
|
|
// same column, row 0 off
|
|
|
|
ledSetMatrix(column, 0, OFF);
|
|
|
|
state = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
state = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-02 16:54:24 +01:00
|
|
|
|
|
|
|
void patternInit() {
|
2019-02-03 23:19:09 +01:00
|
|
|
schAdd(patternExec, NULL, 0, 100);
|
2019-02-02 16:54:24 +01:00
|
|
|
}
|