Hi!
i need some help with this:
my detonator script shows time like this: sss (120) and i want it to show it like this: hh:mm:ss
And also i want it to start detonating only after i press button in pin 8
my lcd is 20x4
arduino uno
original script:
/*
LiquidCrystal Library - display() and noDisplay()
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch prints "Hello World!" to the LCD and uses the
display() and noDisplay() functions to turn on and off
the display.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/
// include the library code:
#include <LiquidCrystal.h>
int timer=2.00; // 120 seconds. (2 minutes)
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int detonatorPin = 13;
int ledPin = 9;
void setup() {
pinMode(detonatorPin, OUTPUT);
pinMode(ledPin, OUTPUT);
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
// Print a message to the LCD.
lcd.print("#########################");
lcd.setCursor(0,1);
lcd.print("#########################");
lcd.setCursor(0,2);
lcd.print("#########################");
lcd.setCursor(0,3);
lcd.print("#########################");
delay(1000);
lcd.clear();
lcd.print("Starting...");
digitalWrite(ledPin, HIGH);
delay(2000);
lcd.clear();
lcd.print("Loading core...");
lcd.setCursor(1,1);
lcd.print("#############");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Loading core...");
lcd.setCursor(1,1);
lcd.print("*############");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Loading core...");
lcd.setCursor(1,1);
lcd.print("****#########");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Loading core...");
lcd.setCursor(1,1);
lcd.print("********#####");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Loading core...");
lcd.setCursor(1,1);
lcd.print("*************");
delay(2000);
lcd.setCursor(2,2);
lcd.print("Core Loaded!");
delay(5000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Status:Connected.");
delay(1000);
lcd.setCursor(6,1);
lcd.print("Armed");
delay(1000);
lcd.setCursor(0,2);
lcd.print("*******READY********");
delay(5000);
digitalWrite(detonatorPin, HIGH);
delay(150);
digitalWrite(detonatorPin, LOW);
delay(500);
digitalWrite(detonatorPin, HIGH);
delay(150);
digitalWrite(detonatorPin, LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Self-destruction in:");
}
void loop() { // This part runs until powered off.
// main code for counting down etc.
if (timer<=0) { // If timer reaches zero, you're toast.
lcd.clear(); // clearing lcd.
delay(2000); // Last two seconds
lcd.setCursor(6,0);
lcd.print("KABOOM!");
lcd.setCursor(4,1);
lcd.print("KABOOM!");
lcd.setCursor(06,2);
lcd.print("KABOOM!");
lcd.setCursor(3,3);
lcd.print("KABOOM!");
digitalWrite(detonatorPin, HIGH); // Bye!
delay(2000); // Two seconds should be enough for detonating.
digitalWrite(detonatorPin, LOW); // Looping this part over and over in case it did not work at first.
}
else{
lcd.setCursor(8, 1); } // if timer value is greater than 0, keep on counting.
// The actual counting down part
while(timer>=0) { // While timer value is greater than zero
lcd.print(timer); // Print timer value to LCD
lcd.setCursor(8, 1); // Just to set the cursor right.
timer--; // Reducing the timer value by one
digitalWrite(ledPin, LOW);
digitalWrite(detonatorPin, LOW);
delay(1000); // wait one second
digitalWrite(detonatorPin, HIGH);
digitalWrite(ledPin, HIGH);
// Next part is purely for the hollywood effect :P
if (timer<=100){ // 100seconds remaining
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Self-destruction in:");
lcd.setCursor(3,2);
lcd.print(" Defuse faster!"); // Where is Jack Bauer when you need him?
lcd.setCursor(8,1); }
if (timer<=60) { // One minute remaining.
lcd.clear();
lcd.setCursor(0,0);
lcd.print("You may escape now!");
lcd.setCursor(2,2);
lcd.print("Time's almost up"); // There's still plenty of time...!
lcd.setCursor(8,1); }
if (timer<=10) {
lcd.clear();
lcd.setCursor(1,0);
lcd.print(" Goodbye"); // Awwwsshhiiit.
lcd.setCursor(8,1); // centering the cursor for last few seconds.
} }
}
thank you allready