diff --git a/Makefile b/Makefile index 22a804b..8e07030 100644 --- a/Makefile +++ b/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 diff --git a/myrand.c b/myrand.c new file mode 100644 index 0000000..7322a17 --- /dev/null +++ b/myrand.c @@ -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; +} \ No newline at end of file diff --git a/myrand.h b/myrand.h new file mode 100644 index 0000000..9cd51f9 --- /dev/null +++ b/myrand.h @@ -0,0 +1,9 @@ +#ifndef MYRAND_H_ +#define MYRAND_H_ + +#include + +uint8_t myrand(); + + +#endif // MYRAND_H_ \ No newline at end of file diff --git a/pattern.c b/pattern.c index 462b6b3..8f4c483 100644 --- a/pattern.c +++ b/pattern.c @@ -2,7 +2,7 @@ #include "led.h" #include "PontCoopScheduler.h" #include - +#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); } \ No newline at end of file