Go Down

Topic: Parallax LCD Countdown Timer (Read 1 time) previous topic - next topic

robtillaart

now let it run for a while and think about how to prefix a leading zero if needed...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

dragonlady92

I figured out a way to make the time start at 0h 0m 0s, but it displays the millis on the next line. which is not ideal. I also put an alarm that goes off after 30 minutes, which is what i need for my project, but I wonder if there is a way to make it count down from 30 minutes instead though?

Code: [Select]

const int TxPin = 6;

#define CLEAR 12
#define BACKLIGHTON 17
#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);

void setup()
{
  pinMode(TxPin, OUTPUT);
  digitalWrite(TxPin, HIGH);
  mySerial.begin(9600);
  delay(100);
  mySerial.write(CLEAR );     
  mySerial.write(BACKLIGHTON );   
  delay(5);                        // Required delay
  mySerial.print("BEGIN TEST");    // First line
  delay(1000);
  mySerial.write(CLEAR );

}

void loop()
{

  //float hours, minutes, seconds;
  unsigned long now = millis();    // internal clock since startup
 
  unsigned long ts = now/1000;     // convert milliseconds to (temporary) seconds
  int hours = ts /3600;            // calculate the hours in ts
  ts = ts - hours * 3600;          // subtract the hours from ts leaving minutes and seconds
  int minutes = ts /60;            // calculate the minutes in ts
  ts = ts - minutes * 60;          // subtract the minutes from ts leaving seconds
  int seconds = ts /1;
  ts = ts - seconds * 1;


  mySerial.write(CLEAR); 
  delay(5);
  mySerial.print(hours);
  mySerial.print("h ");
  mySerial.print(minutes);
  mySerial.print("m ");
  mySerial.print(seconds);
  mySerial.print("s ");

  mySerial.write(148);               //carraige return
  mySerial.print(now);               //display current millis, otherwise the time starts at 1m6s?!

  delay(1000);
 
  if(minutes == 30)
  {
  mySerial.write(220);
  mySerial.write("BOOM");   
  }
 
}

arloG

Quote
it displays the millis on the next line. which is not ideal.

Where do you want it displayed?

Quote
mySerial.write(148);               //carraige return
  mySerial.print(now);               //display current millis, otherwise the time starts at 1m6s?!


Does this carriage return push millis (actually "now") to the next line?  Is this what you consider to be not ideal?

Quote
I wonder if there is a way to make it count down from 30 minutes instead though?

To do this, can you figure out the starting time, add 30 minutes and then subtract the current time from the starting time?  You'll have to change your "Boom" criterion.

Go Up