I am making a simulation time bomb for airsoft. I have the basic code that works but now i need to integrate a timer that starts at 60 and counts down displaying the current time left on the lcd with a beep every other second. I found that this library is the best for what I am trying to do, but I am having trouble with the code. Arduino Playground - CountDownTimer . Below is the code I have so far. With a arm and start switch. Everything works except the timer functions.
#include <CountUpDownTimer.h>
#include <SoftwareSerial.h>
const int lcdpin = 1;
const int ledgreen = 2;
const int ledred = 3;
const int armbutton = 4;
const int startbutton = 5;
const int tpin = 6;
int buttonState = 0;
int buttonState1=0;
int CountUpDownTimer(SetTimer(60))
CountUpDownTimer(DOWN);
SoftwareSerial mySerial = SoftwareSerial(255,lcdpin);
void setup() {
pinMode(lcdpin, OUTPUT);
pinMode(ledgreen, OUTPUT);
pinMode(ledred, OUTPUT);
pinMode(armbutton, INPUT);
pinMode(startbutton, INPUT);
pinMode(tpin, OUTPUT);
}
void loop() {
digitalWrite(lcdpin, HIGH);
mySerial.begin(19200);
delay(5);
mySerial.write(12);
delay(5);
mySerial.write(17);
delay(5);
digitalWrite(ledgreen, HIGH);
mySerial.write("Ready");
while(digitalRead(armbutton)== LOW);
buttonState = digitalRead(armbutton);
if(buttonState == HIGH) {
digitalWrite(ledred, HIGH);
mySerial.write(12);
delay(5);
mySerial.write("Armed");
}
while(digitalRead(startbutton)== LOW);
buttonState1 = digitalRead(startbutton);
if(buttonState1 == HIGH) {
CountUpDownTimer(SetTimer(60));
CountUpDownTimer(StartTimer());
mySerial.write(148);
mySerial.write(CountUpDownTimer(ShowSeconds()));
while(CountUpDownTimer(ShowSeconds()) > 0);
if(CountUpDownTimer(ShowSeconds()) == 0) {
digitalWrite(tpin, HIGH);
}
}
}
airsoft_bomb.ino (1.33 KB)