Random Colour Code

Hi everyone,

I’ve currently got an 8x8 RGB matrix running off an Rainbowduino Atmel 328 hooked up to an Arduino Uno Atmel 328. All is working well and it runs the demo codes fine. I’ve currently got it running the MeggyJr patch and playing the Random Colours code. Currently is initiates a random board of coloured cells, and then changes them randomly for a period of time whilst speeding up the frame rate. It’s meant to have interactive controls as its a MeggJR code, but I’m not interested in this aspect so ignore them. I have altered it so that it doesn’t speed up and stays at a constant frame rate. What I was hoping was if anyone could help me alter the code slightly. I can’t see where you alter the frame rate speed. Secondly, I would like to run the code for a set period of time/frames, pause it, hold that pause for another set time, then re-run the code starting with a new random board etc. etc.

If anyone is able to help that would be fantastic. I have copied the code below, thanks in advance!

Dan


#include <MeggyJrSimple.h> // Required code, line 1 of 2.

unsigned long lasttime;
int delayTime;
byte interactive;
byte ButtonsLast;
byte pause;
byte ColorRange;

byte AuxLEDValue;

void setup() // run once, when the sketch starts
{

MeggyJrSimpleSetup(); // Required code, line 2 of 2.

lasttime = millis();
delayTime = 300;
interactive = 0; // No human contact yet.
pause = 0;

ColorRange = 14;

} // End setup()

void loop() // run over and over again
{

unsigned long TempTime;

byte i;
byte j;
int delayTemp;

CheckButtonsPress();

if (Button_B)   //"B" button            // Resume automatic speed ramps
  interactive = 1;       

if (Button_A)   //"A" button            // Pause/unpause
{interactive = 0; 
  pause = !pause;       
}

// if ((Button_Up) && (delayTime > 0)) // up button: Speed up
{ delayTime -= 10;
interactive = 1;
}

// if ((Button_Down) && (delayTime < 1000)) // down button: Slow down
{ delayTime += 10;
interactive = 1;
}

if ((Button_Left) && (ColorRange > 1))    // left button: reduce # of colors
 {interactive = 1; 
 ColorRange--;
 }
if ((Button_Right) &&  (ColorRange < 14))  // right button: increase # of colors
  {interactive = 1; 
  ColorRange++; 
  }

TempTime = millis();

delayTemp = delayTime - 50;
if (delayTemp < 0)
delayTemp = 0;

if ((TempTime - lasttime) > delayTemp)
{

i = 0;
while (i < 8) { 
  j = 0;
  while ( j < 8)
  {
    DrawPx(i,j, rand() % ColorRange);

    // Randomly pick colors from the color look up table!
    j++;
  }
  i++;
}

if (interactive == 0)
{ 
  if (--delayTime == 0)
      delayTime = 250;
}

AuxLEDValue++;

SetAuxLEDs(AuxLEDValue);

lasttime = TempTime;

if (pause == 0)
   DisplaySlate();  

}

} // End loop()