I am using an Arduino Mega to alternate outputs that feed a clock pin on a 4553 IC. When the start button is pushed, the "Timer" output pin goes HIGH. This pin starts a 555 astable circuit designed for a total Time of 1 sec. It is actually a touch over 1 sec, but this project is for kids so it won't hurt. One other note, based on a previous suggestion, I am using a 1N4148 Diode across R2 on the astable so I have a Duty Cycle of approx. 22%. The thinking was to keep High(time) as low as possible compared to the total Time - just to minimize the possibility of double signals.
This project is a laser maze so if someone is good enough, they would complete the maze without blocking any lasers - the game clock would simply count at a 1-sec pace until the stop button is pressed.
BUT, if/when a laser is blocked, I have a Penalty Circuit designed to add 5 seconds to the total time. My current design uses a 0.1 sec 555 One Shot circuit feeding a second 555 astable designed to approx. 5 "highs" in the 0.1 sec from the One Shot. The Penalty astable output also feeds into the 4553 clock pin.
During the debugging process, I can get the 1-sec 555 to count great. And, if I block the laser and keep it blocked, I can watch the penalty time start running up. In fact, if I stay in the beam, the timer keeps the hyperspeed rate.
But, if I just block the laser for a split second, the penalty time is not added. I do know that the LDR is going dark, because I also have a siren circuit that sounds for 2 secs. The siren sounds for the entire 2 secs (yep, another 555 circuit) even if I run through the laser.
Here is the section of the program that I have been messing with. I only have 2 ldr's/lasers setup now so that is why I have the 3-6 commented out.
if (easyMode == 1 && startMode == 1){
digitalWrite(timer, HIGH);
ldr1Read = analogRead(ldr1);
ldr2Read = analogRead(ldr2);
//ldr3Read = analogRead(ldr3);
//ldr4Read = analogRead(ldr4);
// ldr5Read = analogRead(ldr5);
// ldr6Read = analogRead(ldr6);
if (ldr1Read > 900){
digitalWrite(timer, LOW);
delay(30);
digitalWrite(penalty, HIGH);
delay(110);
digitalWrite(siren, HIGH);
digitalWrite(penalty, LOW);
digitalWrite(siren, LOW);
digitalWrite(timer, HIGH);
}
if (ldr2Read > 850){
digitalWrite(timer, LOW);
delay(30);
digitalWrite(penalty, HIGH);
delay(110);
digitalWrite(siren, HIGH);
digitalWrite(penalty, LOW);
digitalWrite(siren, LOW);
digitalWrite(timer, HIGH);
}
I have tried several ways - no delays, more delays. My thinking for using the 110 delay after the penalty is set High is to allow the penalty cycle to do its damage, but to be honest I have tried several variations and this may be the one that caused the penalty not to show up at all - would that be because the arduino is basically paused during the penalty portion?
This is my first time programming and I have only been doing it for a couple of weeks so go easy and what seems obvious to you is def. not to me.
Thanks in advance for any help provided.