my own random
This commit is contained in:
43
pattern.c
43
pattern.c
@ -2,7 +2,7 @@
|
||||
#include "led.h"
|
||||
#include "PontCoopScheduler.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "myrand.h"
|
||||
|
||||
/*
|
||||
* traversing the whole matrix
|
||||
@ -73,6 +73,7 @@ void patternExec() {
|
||||
void patternExec() {
|
||||
static uint8_t state = 0;
|
||||
static uint8_t column = 0;
|
||||
static uint8_t stay = 0;
|
||||
|
||||
switch (state) {
|
||||
case 0:
|
||||
@ -86,23 +87,47 @@ void patternExec() {
|
||||
break;
|
||||
case 1:
|
||||
// select new column, row 2
|
||||
column = ((uint8_t) rand()) & 0x3;
|
||||
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);
|
||||
state = 3;
|
||||
break;
|
||||
case 3:
|
||||
// same column, row 0
|
||||
ledSetMatrix(column, 0, RED);
|
||||
ledSetMatrix(column, 1, 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;
|
||||
@ -116,5 +141,5 @@ void patternExec() {
|
||||
|
||||
|
||||
void patternInit() {
|
||||
schAdd(patternExec, NULL, 0, 1000);
|
||||
schAdd(patternExec, NULL, 0, 100);
|
||||
}
|
Reference in New Issue
Block a user