my own random
This commit is contained in:
parent
f6f69dd9b2
commit
a31c929053
2
Makefile
2
Makefile
@ -2,7 +2,7 @@ CC=msp430-gcc
|
||||
CFLAGS=-O3 -g0 -Wall -mmcu=msp430g2553 -std=gnu99 -I hottislib
|
||||
LDFLAGS=-mmcu=msp430g2553
|
||||
|
||||
blinky1.elf: main.o led.o time.o pattern.o PontCoopScheduler.o
|
||||
blinky1.elf: main.o led.o time.o pattern.o PontCoopScheduler.o myrand.o
|
||||
$(CC) -o $@ $(LDFLAGS) $^
|
||||
|
||||
PontCoopScheduler.o: hottislib/PontCoopScheduler.c hottislib/PontCoopScheduler.h
|
||||
|
115
myrand.c
Normal file
115
myrand.c
Normal file
@ -0,0 +1,115 @@
|
||||
#include "myrand.h"
|
||||
|
||||
|
||||
uint8_t numbers[] = {
|
||||
220,
|
||||
60,
|
||||
136,
|
||||
163,
|
||||
230,
|
||||
44,
|
||||
255,
|
||||
40,
|
||||
252,
|
||||
66,
|
||||
201,
|
||||
204,
|
||||
142,
|
||||
232,
|
||||
33,
|
||||
26,
|
||||
59,
|
||||
188,
|
||||
68,
|
||||
92,
|
||||
93,
|
||||
58,
|
||||
69,
|
||||
158,
|
||||
193,
|
||||
132,
|
||||
30,
|
||||
152,
|
||||
128,
|
||||
126,
|
||||
23,
|
||||
202,
|
||||
182,
|
||||
126,
|
||||
47,
|
||||
119,
|
||||
131,
|
||||
104,
|
||||
102,
|
||||
38,
|
||||
119,
|
||||
24,
|
||||
203,
|
||||
244,
|
||||
24,
|
||||
216,
|
||||
179,
|
||||
71,
|
||||
186,
|
||||
202,
|
||||
246,
|
||||
64,
|
||||
102,
|
||||
67,
|
||||
168,
|
||||
255,
|
||||
21,
|
||||
104,
|
||||
138,
|
||||
23,
|
||||
220,
|
||||
134,
|
||||
16,
|
||||
196,
|
||||
39,
|
||||
105,
|
||||
214,
|
||||
240,
|
||||
27,
|
||||
122,
|
||||
120,
|
||||
175,
|
||||
72,
|
||||
123,
|
||||
88,
|
||||
229,
|
||||
247,
|
||||
203,
|
||||
85,
|
||||
143,
|
||||
8,
|
||||
232,
|
||||
207,
|
||||
113,
|
||||
236,
|
||||
7,
|
||||
82,
|
||||
195,
|
||||
254,
|
||||
178,
|
||||
77,
|
||||
32,
|
||||
182,
|
||||
150,
|
||||
223,
|
||||
183,
|
||||
246,
|
||||
255,
|
||||
104,
|
||||
72,
|
||||
};
|
||||
|
||||
uint8_t myrand() {
|
||||
static uint16_t i = 0;
|
||||
uint8_t r = numbers[i];
|
||||
i++;
|
||||
if (i > sizeof(numbers)) {
|
||||
i = 0;
|
||||
}
|
||||
return r;
|
||||
}
|
9
myrand.h
Normal file
9
myrand.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef MYRAND_H_
|
||||
#define MYRAND_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
uint8_t myrand();
|
||||
|
||||
|
||||
#endif // MYRAND_H_
|
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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user