Hi.
Working on a 2 lane timer. Got most of it done so far.
Question, I have 2 led blinking when the two timers are running. Just for fun and to learn, I set them at different intervals: Lane1 at 500ms and Lane2 at 200ms.
If I start Lane2 it blinks at 200ms but when I start Lane1 it blinks the same as Lane1, 500ms.
Seem like Lane1 overides Lane2 blinking.
Can’t figure it out.
#include <LiquidCrystal.h> //Seriel LCD Here
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define ledtimingPin 10
#define ledreadyPin 11
#define ledrunoverPin 12
#define startPin 6
#define stopPin 8
#define resetPin 7
// LANE2----------------------------------------------
#define ledtimingPin2 5
#define ledreadyPin2 13
#define ledrunoverPin2 9
#define startPin2 2
#define stopPin2 3
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
int value = LOW; // previous value of the LED
int buttonState1; // variable to store button state 1
int buttonState2; // variable to store button state 2
int lastButtonState1; // variable to store last button state 1
int lastButtonState2; // variable to store last button state 2
int stateReset; // variable to store reset button state
int blinking; // condition for blinking - timer is timing
long interval = 500; // blink interval - change to suit
long previousMillis = 0; // variable to store last time LED was updated
long startTime ; // start time for stop watch
long elapsedTime ; // elapsed time for stop watch
int fractional; // variable used to store fractional part of time
//LANE 2
int value2 = LOW; // previous value of the LED
int buttonState3; // variable to store button state 2
int buttonState4; // variable to store button state 3
int lastButtonState3; // variable to store last button state 3
int lastButtonState4; // variable to store last button state 4
int blinking2; // condition for blinking - timer is timing
long interval2 = 200; // blink interval - change to suit
long previousMillis2 = 0; // variable to store last time LED was updated
long startTime2 ; // start time for stop watch
long elapsedTime2 ; // elapsed time for stop watch
int fractional2; // variable used to store fractional part of time
void setup()
{
Serial.begin(9600);
pinMode(ledtimingPin, OUTPUT); // sets the digital pin as output
pinMode(ledreadyPin, OUTPUT); // sets the digital pin as output
pinMode(ledrunoverPin, OUTPUT); // sets the digital pin as output
pinMode(startPin, INPUT); // not really necessary, pins default to INPUT anyway
pinMode(stopPin, INPUT); // not really necessary, pins default to INPUT anyway
pinMode(resetPin, INPUT); // not really necessary, pins default to INPUT anyway
digitalWrite(startPin, HIGH); // turn on pullup resistors. Wire button so that press shorts pin to ground.
digitalWrite(stopPin, HIGH); // turn on pullup resistors. Wire button so that press shorts pin to ground.
digitalWrite(resetPin, HIGH);
//LANE2
pinMode(ledtimingPin2, OUTPUT); // sets the digital pin as output
pinMode(ledreadyPin2, OUTPUT); // sets the digital pin as output
pinMode(ledrunoverPin2, OUTPUT); // sets the digital pin as output
pinMode(startPin2, INPUT); // not really necessary, pins default to INPUT anyway
pinMode(stopPin2, INPUT); // not really necessary, pins default to INPUT anyway
digitalWrite(startPin2, HIGH); // turn on pullup resistors. Wire button so that press shorts pin to ground.
digitalWrite(stopPin2, HIGH); // turn on pullup resistors. Wire button so that press shorts pin to ground.
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.print(" Slalom Timer"); // Print a message to the LCD
lcd.setCursor(0, 1);
lcd.print(" Timer ready!");
digitalWrite(ledreadyPin, HIGH);
digitalWrite(ledrunoverPin, LOW);
//---LANE2-
digitalWrite(ledreadyPin2, HIGH);
digitalWrite(ledrunoverPin2, LOW);
}
void loop()
{
buttonState1 = digitalRead(startPin); // read the start button state and store
buttonState2 = digitalRead(stopPin); // read the stop button state and store
stateReset = digitalRead(resetPin); // read the reset button state and store
if (buttonState1 == LOW && lastButtonState1 == HIGH) // check for a high to low transition
{
if(!blinking) // if true then found a new button press while clock is not running - start the clock
startTime = millis(); // store the start time
blinking = true; // turn on blinking while timing
delay(5); // short delay to debounce switch
lastButtonState1 = buttonState1; // store buttonState1 in lastButtonState1, to compare next time
//lcd.clear();
lcd.setCursor(0, 0);
lcd.print("L1 Running....");
digitalWrite(ledreadyPin, LOW);
}