Pages: [1]   Go Down
Author Topic: "Hollywood style" timer & "detonator"  (Read 1137 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi.
This is a learning project just to teach myself IF and WHILE functions and testing my newly obtained LCD screen.
Basicly this code makes arduino count down from 120 while printing value on screen and when timer reaches zero, detonatorPin goes high.
Code is buggy and crappy and all that, so i appreciate any comments and improvements!

Also sorry for my crappy english smiley

-J

Code:
/* Detonator 1.0 By Joona.
   Just a joke. Not to be
   used in anything illegal
   or to endanger any human
   or other life.
   Creator is not responsible
   or liable in any way
   for misuse of this
   piece of software. */
  
/* Wiring LCD:
   RW - To ground
   RS - To digital pin 7
   ENABLE - To digital pin 8
   DB7 - To digital pin 12
   DB6 - To digital pin 11
   DB5 - To digital pin 10
   DB5 - To digital pin 9
   Wiring rest:
   digital pin 4 - To led or similiar. */


#include <LiquidCrystal.h> // LCD-Library
int timer=120; // 120 seconds. (2 minutes)  


LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // defining pins used by lcd.
int detonatorPin = 4; // defining pin used by detonator


void setup() { // This part runs once.
pinMode(detonatorPin, OUTPUT); // defining detonator pin as output
  // Setting up the LCD. I used 16*4
  lcd.begin(16, 4); // Starting up
  // Printing the version
  lcd.print("  Detonator 1.0");
}

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(2,1);
lcd.print("   KABOOM!"); // This reminds you, that this is just a joke.
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(2, 3); } // 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(2, 3); // Just to set the cursor right.
    timer--; // Reducing the timer value by one
  delay(1000); // wait one second
  // Next part is purely for the hollywood effect :P
  if (timer<=100){ // 100seconds remaining
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(" Defuse faster!"); // Where is Jack Bauer when you need him?
    lcd.setCursor(2,3); }
  if (timer<=60) { // One minute remaining.
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Time's almost up"); // There's still plenty of time...!
    lcd.setCursor(2,3); }
     if (timer<=10) {
       lcd.clear();
       lcd.setCursor(0,0);
       lcd.print("     Goodbye");  // Awwwsshhiiit.
    
    lcd.setCursor(3,3); // centering the cursor for last few seconds.
  } }

  
}
Logged

Massachusetts (unfortunately)
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
I wish I was where I am
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah but to be truly a Hollywood-style detonator it needs to use an LED display! smiley
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah. You are right. That's why I used quotation marks  ;D
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Yeah but to be truly a Hollywood-style detonator it needs to use an LED display!

That also freezes at 1 when the good guy cuts the blue wire, or is it the red wire?

Lefty
Logged

Massachusetts (unfortunately)
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
I wish I was where I am
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah and it needs to stop just before it goes off and tell you it's whole evil master plan and how you can't win, giving you just enough time to stop it.
Logged

Pages: [1]   Go Up
Jump to: