Hi, i'm new to arduino so i don't know much (yet
) but i'm working on an device for airsoft simulation that will light a pyro when the countdown hits 00:00
I saw a project on the internet and got the parts and code and it works.. but not quite in the way i would like it to.
First thing i would like to modify is the code that is already working. It uses a potentiometer to adjust the time to countdown (5s-60s) but i want to be able to count down from 10s or 9999s 10s being min time & 9999s being max time
Another thing is, the guy who wrote the code made it that only 3 digits are used but i would like to use all 4
I'm using a
7-Segment Serial Display - Red - COM-11441 - SparkFun for the display
The code and schematic are posted below
If anyone can help me the would be much appreciated
Thanks
/*RocketLauncher
ROCKET LAUNCHER CONTROLLER.
Arduining.com 05 Jan 2012 (hardware implemented version)
-A count-down TIMER is implemented.
-The potentiometer is used to set the TIMER.
-Two Push-Buttons: "ARM" to set the counter and "GO" to start the counter.
-Display: Sparkfun's Serial 4 Digit 7-Segment Display . COM-09766 (RED).
-SoftwareSerial library is used to avoid random commands to the display
during program downloading.
*/
#define FuseTIME 1500 //Fuse current duration in milliminute.
#include <SoftwareSerial.h> //Usinf the SoftwareSerial library.
#define Fuss 7 //Pin connected to the Fuse relay.
#define GoButt 8 //Pin connected to the GO button.
#define ArmButt 9 //Pin connected to the ARM button.
#define BuzzPin 4 //Connected to the Speaker.
#define TXdata 3 //Conneted to Rx of the Display.
#define RXdata 2 //not used in this project
#define SetPot 0 //Analog Pin connected to the Pot.
SoftwareSerial mySerialPort(RXdata,TXdata);
void setup(){
pinMode(TXdata,OUTPUT);
pinMode(RXdata,INPUT);
pinMode(Fuss,OUTPUT);
pinMode(ArmButt, INPUT); // set "ARM" button pin to input
pinMode(GoButt, INPUT); // set "GO" button pin to input
digitalWrite(Fuss,LOW); //OPEN the fuse circuit.
digitalWrite(ArmButt, HIGH); // turn on pullup resistor
digitalWrite(GoButt, HIGH); // turn on pullup resistor
mySerialPort.begin(9600);
delay(10); //Wait for Serial Display startup.
mySerialPort.print("v"); //Reset the display.
mySerialPort.print("z"); //Brightness Control.
mySerialPort.write(0x40); //3/4 Intensity.
}
int DownCntr; // down counter (1/10 Secs.)
int Go=0; // Stopped
//================================================================
void loop(){
if(!digitalRead(GoButt)||!digitalRead(ArmButt)){
Go=0; //ABORT!!!
tone(BuzzPin, 440, 1500);
delay(1500);
}
if(Go==0){
WaitARM();
WaitGO();
}
ShowTimer();
if (DownCntr > 50){
if (DownCntr % 10 ==0)tone(BuzzPin, 1000, 50); //Tone every second.
}
else if (DownCntr % 2 ==0)tone(BuzzPin, 1000, 50); //Tone every 1/5 second.
if (DownCntr ==0){
//------------------ ROCKET LAUNCH! --------------------
tone(BuzzPin, 440, FuseTIME); //Launch audible signal
digitalWrite(Fuss,HIGH); //CLOSE the fuse circuit
delay(FuseTIME);
delay(FuseTIME);
delay(FuseTIME);
delay(FuseTIME);
digitalWrite(Fuss,LOW); //OPEN the fuse circuit.
//------------------------------------------------------
Go=0;
}
while (millis()% 100); //Wait until the next 1/10 of second.
delay(50);
DownCntr--;
}
//----------------------------------------
void WaitGO(){
ShowTimer();
while(digitalRead(GoButt));
Go=1;
delay(20);
while(!digitalRead(GoButt)); //Debounce GO button.
}
//------------------------------------------------------
void ReadTimer(){
DownCntr = map(analogRead(SetPot), 0, 1023, 5, 99);
DownCntr*=10;
}
//------------------------------------------------------
void ShowTimer(){
String minute = String (DownCntr, DEC);
while(minute.length()<3)minute= "0" + minute; //format to 3 numbers.
mySerialPort.print(minute); //Write to Display.
mySerialPort.print("0"); //Last digit off.
}
//------------------------------------------------------
void WaitARM(){
while(digitalRead(ArmButt)==1){
ReadTimer();
delay(50);
ReadTimer();
ShowTimer(); //Show Digits.
delay(150);
}
Go=0;
ShowTimer();
tone(BuzzPin, 2000, 150);
delay(200);
tone(BuzzPin, 2000, 150);
delay(200);
tone(BuzzPin, 2000, 150);
delay(20);
while(!digitalRead(ArmButt)); //Debounce ARM button.
}

