hi
question: i want to have a delay of 13min between the changes. the problem is that the code runs a fist time complet (means with the 13 min delay) before the leds are the first time blinking.
where i have to place the (LIGHTOFF_DELAY) to run the leds at the beginning when i turn on the arduino ?
//http://arduino.cc/en/Reference/Const
const long LIGHT_DELAY = 110000;
const long LIGHTOFF_DELAY = 780000;
const byte MATRIX_WIDTH = 6;
const byte MATRIX_HEIGHT = 6;
//hold the pin numbers of the matrix
const byte matrix[MATRIX_HEIGHT][MATRIX_WIDTH] = {
{ 2, 3, 4 }, //matrix[0][0] , matrix[0][1] , matrix[0][2]
{ 5, 6, 7 }, //matrix[1][0] , matrix[1][1] , matrix[1][2]
{ 8, 9, 10 }, //matrix[2][0] , matrix[2][1] , matrix[2][2]
{ 2, 5, 8 }, //matrix[0][0] , matrix[0][1] , matrix[0][2]
{ 3, 6, 9 }, //matrix[1][0] , matrix[1][1] , matrix[1][2]
{ 4, 7, 10 }, //matrix[2][0] , matrix[2][1] , matrix[2][2]
};
void setup(){
//set pins as OUTPUT
for (byte y=0; y<MATRIX_HEIGHT; y++){
for (byte x=0; x<MATRIX_WIDTH; x++){
pinMode( matrix[y][x] , OUTPUT );
}
}
//http://arduino.cc/en/Reference/RandomSeed
randomSeed(analogRead(0));
}
void loop(){
//http://arduino.cc/en/Reference/Random
boolean doLightColumn = random(1);
if (doLightColumn){
//select a random index
byte idx = random(MATRIX_WIDTH);
//light the column at that index
lightColumn( idx );
} else {
//select a random index
byte idx = random(MATRIX_HEIGHT);
//light the row at that index
lightRow( idx );
}
//make actions visible
delay(LIGHT_DELAY);
}
void lightColumn( byte idx ){
matrixOff();
for (byte y=0; y<MATRIX_HEIGHT; y++){
digitalWrite( matrix[y][idx] , HIGH );
}
}
void lightRow( byte idx ){
matrixOff();
for (byte x=0; x<MATRIX_HEIGHT; x++){
digitalWrite( matrix[idx][x] , HIGH );
}
}
void matrixOff(){
for (byte y=0; y<MATRIX_HEIGHT; y++){
for (byte x=0; x<MATRIX_WIDTH; x++){
digitalWrite( matrix[y][x] , LOW );
}
}
delay(LIGHTOFF_DELAY);
}