LED Timer

So, I'm working on a call timer and trying to get LEDs to react to certain commands upon a given time frame. I have downloaded the Timer.h library and this does not seem to do the trick. I have a LCD that is counting the time (milli). So after x amount of time for example lets say 20 sec I want a led to light. Does anyone have any ideas? The sketch I have listed below is so cut up, broken and battered... please don't judge.. LOL!

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int ledR = 9; //red LED
int ledY = 8; // yellow LED
int ledG = 7; //green LED
unsigned long time;

void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
// Print a message to the LCD.
lcd.print("Call Time");

pinMode(ledR,OUTPUT);
pinMode(ledY,OUTPUT);
pinMode(ledG,OUTPUT);

}

void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000)

{
if (time =< 20)
{
digitalWrite(ledG, HIGH);
}
else
{
digitalWrite(ledG, LOW);
}

}
}

Peter9DO:
So, I'm working on a call timer and trying to get LEDs to react to certain commands upon a given time frame. I have downloaded the Timer.h library and this does not seem to do the trick. I have a LCD that is counting the time (milli). So after x amount of time for example lets say 20 sec I want a led to light. Does anyone have any ideas? The sketch I have listed below is so cut up, broken and battered... please don't judge.. LOL!

It is much harder when you start with something that doesn't work.

try this and see if you can get it to work:

#include <LiquidCrystal.h>
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int ledR = 9; //red LED
int ledY = 8; // yellow LED 
int ledG = 7; //green LED
int buttonPin = 6;
unsigned long oneSecond = 1000UL;
unsigned long lastTime;
unsigned long startFlash;
unsigned long startTime;
int myMinutes;
int mySeconds;
int counter;
byte lastState;
//
void setup() 
{
  // set up the LCD's number of columns and rows: 
  lcd.begin(20, 4);
  lcd.setCursor(0, 0);
  lcd.print("Call Time:");
  pinMode(ledR,OUTPUT);
  pinMode(ledY,OUTPUT);
  pinMode(ledG,OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
}
//
void loop() 
{
  //This Block used to reset your timer with a pushbutton switch
  byte buttonState = digitalRead(buttonPin);
  if (buttonState)
  {
    if (buttonState != lastState)
    {
      startTime = millis();
      lastTime = startTime;
    }
  }
  lastState = buttonState;
  //--------------------------------------------------------------
  if (millis() - lastTime >= oneSecond)
  {
    unsigned long elapsedSeconds = startTime / oneSecond;  // ERROR WAS HERE
    myMinutes = elapsedSeconds / 60;
    mySeconds = elapsedSeconds % 60;
    lcd.setCursor(0, 1);
    if (myMinutes < 10)
    {
      Serial.print("0");
      lcd.print("0");
    }
    Serial.print(myMinutes);
    lcd.print(myMinutes);
    Serial.print(":");
    lcd.print(":");
    if (mySeconds < 10)
    {
      Serial.print("0");
      lcd.print("0");
    }
    Serial.println(mySeconds);
    lcd.print(mySeconds);
    counter++;
    lastTime += oneSecond;
  }
  if (millis() - startTime >= 20000UL) // this is your 20 Second LED liter
  {
    flashRed();
  }
}
//
void flashRed()
{
  if (millis() - startFlash >= 50UL)
  {
    digitalWrite(ledR, !digitalRead(ledR));
    startFlash += 50UL;
  }
}

You have this line in your program
if  (time =< 20)but as the time variable is never updated after it is declared and initialised to zero the test is meaningless.

Try setting time = millis()/1000 just before the test.
Incidentally, the outer braces around your if/else are unnecessary and your program will not compile because of the missing semi-colon on  lcd.print(millis()/1000) and =< needs to be <= in the test

Thank to everyone for responding and your willingness to assist. I started working on BulldogLowell's sketch, which is EXCELENT, with some minor changes I should have this project up and running in no time. Thank you very much, it would have been months for me to come up with code this great! This project is a tool that I will be using at my place of employment to assist me with keeping track of my call times and providing warning led notifications when I need to try to wrap it up... Again, thank you very much!

BulldogLowell:

Peter9DO:
So, I'm working on a call timer and trying to get LEDs to react to certain commands upon a given time frame. I have downloaded the Timer.h library and this does not seem to do the trick. I have a LCD that is counting the time (milli). So after x amount of time for example lets say 20 sec I want a led to light. Does anyone have any ideas? The sketch I have listed below is so cut up, broken and battered... please don't judge.. LOL!

It is much harder when you start with something that doesn't work.

try this and see if you can get it to work:

#include <LiquidCrystal.h>

//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int ledR = 9; //red LED
int ledY = 8; // yellow LED
int ledG = 7; //green LED
int buttonPin = 6;
unsigned long oneSecond = 1000UL;
unsigned long lastTime;
unsigned long startFlash;
unsigned long startTime;
int myMinutes;
int mySeconds;
int counter;
byte lastState;
//
void setup()
{
  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);
  lcd.setCursor(0, 0);
  lcd.print("Call Time:");
  pinMode(ledR,OUTPUT);
  pinMode(ledY,OUTPUT);
  pinMode(ledG,OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
}
//
void loop()
{
  //This Block used to reset your timer with a pushbutton switch
  byte buttonState = digitalRead(buttonPin);
  if (buttonState)
  {
    if (buttonState != lastState)
    {
      startTime = millis();
      lastTime = startTime;
    }
  }
  lastState = buttonState;
  //--------------------------------------------------------------
  if (millis() - lastTime >= oneSecond)
  {
    unsigned long elapsedSeconds = millis() / oneSecond;
    myMinutes = elapsedSeconds / 60;
    mySeconds = elapsedSeconds % 60;
    lcd.setCursor(0, 1);
    if (myMinutes < 10)
    {
      Serial.print("0");
      lcd.print("0");
    }
    Serial.print(myMinutes);
    lcd.print(myMinutes);
    Serial.print(":");
    lcd.print(":");
    if (mySeconds < 10)
    {
      Serial.print("0");
      lcd.print("0");
    }
    Serial.println(mySeconds);
    lcd.print(mySeconds);
    counter++;
    lastTime += oneSecond;
  }
  if (millis() - startTime >= 20000UL) // this is your 20 Second LED liter
  {
    flashRed();
  }
}
//
void flashRed()
{
  if (millis() - startFlash >= 50UL)
  {
    digitalWrite(ledR, !digitalRead(ledR));
    startFlash += 50UL;
  }
}

You might find this video useful.

PS, how did you get to almost 100 posts and not know about code tags..... 8)

I don't get to spend as much time as I would like to, playing with my Arduino. I will use it for a couple of weeks and I have to go back and learn all the basics all over again, seeing the gap in between uses are so long. So its difficult to learn everything all over again, I would blame my lack of consistency on not knowing some of the basics.