Go Down

Topic: detonator (Read 1 time) previous topic - next topic

arttu97

Aug 27, 2012, 05:16 pm Last Edit: Aug 27, 2012, 05:18 pm by arttu97 Reason: 1
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:
Code: [Select]
/*
 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

BulletMagnet83

#1
Aug 27, 2012, 05:48 pm Last Edit: Aug 27, 2012, 05:52 pm by BulletMagnet83 Reason: 1
Something like this you mean?

http://www.youtube.com/watch?v=NDKBuHGwYBA

EDIT: I apologise for the video quality :p I have a much better phone these days.

I did a few "fake IED" prop things for airsoft and paintball games, but went over to 7-segment based displays as they're just easier and make for an ever-so-slightly more realistic counter-terrorist sim game. They're so cheap and simple you could stash loads of them all over the site and make it a real challenge to track down and defuse them all within the game time limit!

Have some code - I don't make them like this any more so feel free to do what you want with it (except make an ACTUAL bomb, of course). It's not the best bit of programming in the world but as you can see, it does work.

Code: [Select]


// Countdown Timer Version 1
// By BulletMagnet83
// For ATmega328 & Arduino

#include <LiquidCrystal.h>


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


int seconds = 10;
int minutes = 0;

long previousMillis = 0;
long interval = 1000;

void setup () {
 
 pinMode(A0, INPUT); // seconds button
 digitalWrite(A0, HIGH); // turn on pullup resistor
 
 pinMode(A1, INPUT); // minutes button
 digitalWrite(A1, HIGH); // turn on pullup resistor
 
 pinMode(A2, INPUT); // start button
 digitalWrite(A2, HIGH); // turn on pullup resistor
 
 pinMode(A3, INPUT); // reset count button
 digitalWrite(A3, HIGH); // turn on pullup resistor
 
 lcd.begin(16, 2); // configure lcd for 16 columns 2 rows
 
}


void delaySet () {
 
 
 lcd.setCursor(0, 0);
 lcd.print("SET DELAY TIME");
 lcd.setCursor(0, 1);
 if(minutes < 10) {
   lcd.print("0");
   lcd.print(minutes);
 }
 else {
   lcd.print(minutes);
 }
 lcd.print(":");
 if(seconds < 10) {
   lcd.print("0");
   lcd.print(seconds);
 }
 else {
   lcd.print(seconds);
 }
 
 if(digitalRead(A0) == LOW) {
   seconds++;
   tone(7, 1400, 10);
   delay(200);
 }
 
 if(digitalRead(A1) == LOW) {
   minutes++;
   tone(7, 1400, 10);
   delay(200);
 }
 
 if(digitalRead(A2) == LOW) {
   countDown ();
 }
 
 if(digitalRead(A3) == LOW) {
   seconds = 10;
   minutes = 0;
   tone(7, 2800, 10);
   delay(100);
   tone(7, 2800, 10);
   
 }
 
 
 
 if(seconds > 59) {
   seconds = 0;
   minutes++;
 }
 
 if(minutes > 59) {
   minutes = 0;
 }

}



void countDown () {
 
 while(1) {

lcd.setCursor(0, 0);
 lcd.print("TIME REMAINING:");
 
  lcd.setCursor(0, 1);
 if(minutes < 10) {
   lcd.print("0");
   lcd.print(minutes);
 }
 else {
 lcd.print(minutes);
 }
 lcd.print(":");
 if(seconds < 10) {
   lcd.print("0");
   lcd.print(seconds);
 }
 else {
 lcd.print(seconds);
}
 
 static unsigned long lastTick = 0;
 
 if (millis() - lastTick >= 1000) {
 lastTick = millis();
 seconds--;
 if(minutes == 0 && seconds < 11) {
 tone(7, 2800, 50);
 }
 else {
   tone(7, 1400, 10);
 }
 }
 
 
 
 
 if(seconds < 0) {
   minutes--;
   seconds = 59;
 }
 if(minutes + seconds == 0) {
 
   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print("YOU'RE FUCKED");
   lcd.setCursor(0, 1);
   
   lcd.print("00:00");
   
   
   
   while(1) {
   }
 }

 }
}
 
 
void loop () {
 
 delaySet ();

}


codlink

Quote
This video is private
//LiNK

BulletMagnet83

Oh piss it... hang on, I'll un-private it!  :smiley-sweat:

arttu97

can you add schematic???

BulletMagnet83

No, because I don't have one. Sorry! But what pins are used for what function is implied in the program itself, I'm sure you can work it out. My LCD pin usage is identical to yours, and hooking up a few buttons and a sounder (if desired) should be a no-brainer, right? :)

Since I started doing my wargaming props differently I stopped maintaining the project and didn't bother going back to LCDs for it - you now have as much material as I do.

Go Up