Go Down

Topic: "Hollywood style" timer & "detonator" (Read 2272 times) previous topic - next topic


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 :)


Code: [Select]
/* 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.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.
 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.print(" Defuse faster!"); // Where is Jack Bauer when you need him?
   lcd.setCursor(2,3); }
 if (timer<=60) { // One minute remaining.
   lcd.print("Time's almost up"); // There's still plenty of time...!
   lcd.setCursor(2,3); }
    if (timer<=10) {
      lcd.print("     Goodbye");  // Awwwsshhiiit.
   lcd.setCursor(3,3); // centering the cursor for last few seconds.
 } }



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


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


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?



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.

Go Up