Skip to content

Commit

Permalink
Add a function to seed the PRNG. To do it we store some a seed in EEP…
Browse files Browse the repository at this point in the history
…ROM and read it at setup().

Also tidied up program 6 by reducing the number of loops by 4.

Program 0 (no-op) now delays for a fixed 30 seconds in the loop()
  • Loading branch information
Lisa Seelye committed Aug 14, 2010
1 parent 3d4cced commit ab3adf6
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions beacon2.pde
@@ -1,4 +1,5 @@
#include <Wire.h>
#include <EEPROM.h>

#define MAX_I2C_RETRIES 100
#define RANDOM_COLOUR (byte)random(1,8)
Expand All @@ -8,6 +9,8 @@
#define RANDOM_RUNS (int)random(200,300)
#define RANDOM_RUN_DELAY (int)random(100,250) //250ms to 1s

#define RANDOMSEED_EEPROM_LOC 0x5

// #define DO_TESTPROGRAM
#define PROGRAMTEST_DELAY 1000

Expand Down Expand Up @@ -79,6 +82,7 @@ loop_state loopstate;
void setup() {
int i;

set_random();
for (i = 0; i < 31; i++)
pinMode(i,OUTPUT);

Expand Down Expand Up @@ -118,6 +122,7 @@ void setup() {

loopstate = LOOP_INIT;
Wire.begin();

#ifdef DO_TESTPROGRAM
programtest(1,layer);
#endif
Expand All @@ -135,7 +140,7 @@ void loop() {
case LOOP_GO:
switch (RANDOM_PROGRAM) {
case 0:
program0(RANDOM_RUNS, RANDOM_RUN_DELAY, layer);
delay(30000); /* No op, let's let the slaves sleep! */
break;
case 1:
program1(RANDOM_RUNS, RANDOM_RUN_DELAY, layer);
Expand Down Expand Up @@ -166,6 +171,13 @@ void loop() {
break;
}
}

inline void set_random() {
randomSeed(EEPROM.read(RANDOMSEED_EEPROM_LOC));
EEPROM.write(RANDOMSEED_EEPROM_LOC,random(255));
return;
}

inline void set_led_status(struct layer layer, const byte led_idx, const byte colour) {
int retried = 0;
layer.leds[led_idx].colour = colour;
Expand Down Expand Up @@ -225,13 +237,6 @@ void programtest( const int runs, struct layer layer[]) {
}


/* No op */
void program0( const int runs, const int round_delay, struct layer layer[]) {
delay(runs * round_delay);
return;
}


/* Program 1:
* (5 on) Offset LEDs in each layer rotate around the axis with random colour choice for each vertical frame:
* x x x x x x x x x
Expand Down Expand Up @@ -458,17 +463,13 @@ void program6(const int runs, const int round_delay, struct layer layer[]) {
going_up = false;
for (j = 0; j < 10; j++) {
set_led_status(layer[4], j, DARK);
}
for (j = 0; j < 10; j++) {
set_led_status(layer[3], j, colour);
}
cur_layer = 3;
}
else {
for (j = 0; j < 10; j++) {
set_led_status(layer[cur_layer], j, DARK);
}
for (j = 0; j < 10; j++) {
set_led_status(layer[cur_layer + 1], j, colour);
}
cur_layer += 1;
Expand All @@ -480,17 +481,13 @@ void program6(const int runs, const int round_delay, struct layer layer[]) {
going_up = true;
for (j = 0; j < 10; j++) {
set_led_status(layer[cur_layer], j, DARK);
}
for (j = 0; j < 10; j++) {
set_led_status(layer[1], j, colour);
}
cur_layer = 1;
}
else {
for (j = 0; j < 10; j++) {
set_led_status(layer[cur_layer], j, DARK);
}
for (j = 0; j < 10; j++) {
set_led_status(layer[cur_layer - 1], j, colour);
}
cur_layer -= 1;
Expand Down

0 comments on commit ab3adf6

Please sign in to comment.