I have been adding features to the laser maze with great results. My sketch now has Sudden Death and Speed Round choices. The Sudden Death portion ends the course when any laser is blocked while the Speed Round lets the kids finish, but penalty time is added.
I quickly realized the kids were avoiding the more challenging areas of the course, so I added an illuminated PB in a strategic location to increases the difficulty. The PB blinks at the start of the run and it MUST be pressed or the Stop button will not stop their time.
But, I have noticed an issue and I am not sure what/why it is happening. I have inserted the function I wrote to control the illuminated PB (target). The entire sketch is quite large, so I have only included the portions specific to the target1 function.
What I Am Seeing:
When the target1Control function is placed within the Sudden Death or Speed Round functions, the sketch works, but the actual blink rate does not correspond to the sketch blink rate. I am not sure how, but something seems to be interfering with the sketch.
If I place the target1Control function at the beginning of the loop function, the actual blink rate matches the sketch blink rate. When I press/select the type of game I want (Sudden Death or Speed Round), the blinking is still correct.
But, when I press the difficulty level (easy, medium or ninja), the blink rate slows considerably. If I then press Start and run the course, the sketch works as planned - I must press the target PB or the Stop button will not work - even though the PB blinking is whacked.
Note: The lasers turn on when the difficulty level is selected.
I think I may have a power supply problem/interference, but I wanted to post the function for your review as well.
My entire project has 4 different power supplies.
Lasers: Dedicated 5V Supply
Illuminated PB's and Siren: 12V Supply
Timer Circuits and Arduino: 9V Supply
Large 5" Displays: 20V Supply
Even though the lasers are the only components using the 5V supply, when the laser power on there is some sort of influence over the arduino/sketch/12V supply? Any ideas?
I quickly realized the kids were avoiding the more challenging areas of the course, so I added an illuminated PB in a strategic location to increases the difficulty. The PB blinks at the start of the run and it MUST be pressed or the Stop button will not stop their time.
But, I have noticed an issue and I am not sure what/why it is happening. I have inserted the function I wrote to control the illuminated PB (target). The entire sketch is quite large, so I have only included the portions specific to the target1 function.
What I Am Seeing:
When the target1Control function is placed within the Sudden Death or Speed Round functions, the sketch works, but the actual blink rate does not correspond to the sketch blink rate. I am not sure how, but something seems to be interfering with the sketch.
If I place the target1Control function at the beginning of the loop function, the actual blink rate matches the sketch blink rate. When I press/select the type of game I want (Sudden Death or Speed Round), the blinking is still correct.
But, when I press the difficulty level (easy, medium or ninja), the blink rate slows considerably. If I then press Start and run the course, the sketch works as planned - I must press the target PB or the Stop button will not work - even though the PB blinking is whacked.
Note: The lasers turn on when the difficulty level is selected.
I think I may have a power supply problem/interference, but I wanted to post the function for your review as well.
My entire project has 4 different power supplies.
Lasers: Dedicated 5V Supply
Illuminated PB's and Siren: 12V Supply
Timer Circuits and Arduino: 9V Supply
Large 5" Displays: 20V Supply
Even though the lasers are the only components using the 5V supply, when the laser power on there is some sort of influence over the arduino/sketch/12V supply? Any ideas?
Rich (BB code):
const int target1 = 18; //PB in course that must be pushed
const int lightTarget1 = 17; //Controls bulb for illuminated Target1
int target1Mode = 0;
int target1State;
int target1V1;
int target1V2;
int lightTarget1State = LOW; //target1State used to blink bulb
long previousTarget1Millis = 0; //will store last time target1 was updated
long target1Interval = 250; // interval at which to blink target1 bulb - .5 sec total .25 on .25 off
void setup(){
pinMode(target1, INPUT_PULLUP);
pinMode(lightTarget1, OUTPUT);
target1State = digitalRead(target1);
}
void loop(){
target1V1 = digitalRead(target1);
delay(2);
target1V2 = digitalRead(target1);
if (target1V1 != target1State || target1V2 != target1State){
target1Mode = 1;
}
}
void target1Control(){
if (target1Mode == 0){
//start the .5 sec toggle after game starts
unsigned long currentTarget1Millis = millis();
if(currentTarget1Millis - previousTarget1Millis > target1Interval) {
// save the last time you changed the bulb power
previousTarget1Millis = currentTarget1Millis;
// if the bulb is off turn it on and vice-versa:
if (lightTarget1State == LOW)
lightTarget1State = HIGH;
else
lightTarget1State = LOW;
// set the bulb with the target1State of the variable:
digitalWrite(lightTarget1, lightTarget1State);
}
}
if (target1Mode == 1){
digitalWrite(lightTarget1, HIGH);
}
}