I am an engineering design student, and I am using Arduino to create a schematic for my design project. The program I am trying to write is a continuous loop with only one function. That function is to measure the time in between button presses and turn on an LED when the time after the second button press is exactly half of the elapsed time between the first and second presses. That is, the first press starts the timer, the second gets the value of elapsed time between the first and second, the third gets the value between the second and third, so on and so forth. While that timing loop happens, an LED is controlled so that the elapsed time between 1 and 2 is divided by two, and when the time between 2 and 3 reaches that time divided by two, the LED flashes.
I will attach the program so far, and I have put pseudocode on each line to help you understand my thought process.
I am an engineering design student, and I am using Arduino to create a schematic for my design project.
A schematic is a symbolic circuit drawing.
I think you mean "sketch", which is also normally a drawing, but in Arduino jargon it's a computer program...
I'm getting a little lost in your logic... Your sketch implies 4 LEDs (red, blue, green, and "output" connected to pin 12, but you only mention one LED in your verbal description...
What's working and what's not working?
The best way to debug (and to develop) code is to work on one thing at a time.
Do your LEDs work? i.e. Just write to the LEDs one at a time to make sure they are working under software control with no user-input.
Does your button work? i.e. Read the button and light an LED.
To diagnose the timing, use the serial monitor to look at timing variables.
if (buttonState == LOW && lastButtonState == HIGH && green == false)There are 4 binary variables, and that means 16 different possibilities. I don't think you've accounted for all 16 possibilities... Or, did you just want to skip that code if none of the if-conditions or if-else conditions are met?
If some of those 16 combinations are invalid or "impossible", you might want to add a final "catch all" else-condition and send the variables to the serial monitor so you can debug the invalid state if it happens.
Alright. To address your question on the number of LED's, I'm using the RGB LED (in pins 9, 10, and 11) to exhibit the variables "blue" and "green". The yellow LED (connected to 12) is the output that flashes in between button pushes. Red is not really needed in the sketch, so I deleted its variable, so that reduces it down to 8 possibilites.
Originally, I used the stopwatch program that was posted on the Playground page, and just added in the part that made the other LED flash, but that does not allow for continuous timing, what I'm looking for in timing is similar to a stopwatch with a lap counter, where you push a button, and it continues to time, but remebers when you pushed the button.
EDD_Student:
... that does not allow for continuous timing, what I'm looking for in timing is similar to a stopwatch with a lap counter, where you push a button, and it continues to time, but remebers when you pushed the button.
See the 'Blink Without Delay' sketch in either the IDE or Examples page of this site.