Hi All,
I am making a model rocket launch controller, it features a safety, Arm switch, a launch button, and a 16x2 LCD display. So to launch the rocket you Arm the Rocket by flipping the arming switch. Then you turn the saftey key, which is an electronic safety. A HIGH signal is passed through the key switch, which allows the rocket to launch. here is my current code.
#include <LiquidCrystal.h> LiquidCrystal lcd(2,3,4,5,6,7); //Define Booleans boolean Armed = true; boolean Safe = true; boolean DeArmedTestPassed = false; boolean HasLaunched = false; boolean Launch = false; //Define Pins int ArmPin = 8; int SafePin = 9; int LaunchPin = 10; int Piezo = 11; int Igniter = 12; int SwitchLed = 13; int PotPin = 0; char * erase = " "; int PotVal = 0; void setup() { pinMode(ArmPin, INPUT); pinMode(SafePin, INPUT); pinMode(PotPin, INPUT); pinMode(LaunchPin,INPUT); Serial.begin(9600); lcd.begin(16,2); for(int i = 0; i <= 2; i++) { lcd.setCursor(0,0); lcd.println(" Welcome To "); lcd.setCursor(0,1); lcd.println(" Rocket Launch 1 "); delay(1000); lcd.setCursor(0,1); lcd.println(erase); lcd.setCursor(0,0); lcd.println(erase); delay(1000); } lcd.clear(); for(int j = 1; j < 3; j++) // CHANGE ME { lcd.setCursor(0,0); lcd.print(" Loading "); //10 delay(500); lcd.setCursor(10,0); lcd.print("."); delay(500); lcd.setCursor(11,0); lcd.print("."); delay(500); lcd.setCursor(12,0); lcd.print("."); delay(500); } lcd.clear(); if(digitalRead(ArmPin) == HIGH) DeArmedTestPassed = false; else if(digitalRead(ArmPin) == LOW) DeArmedTestPassed = true; digitalWrite(13,LOW); } void loop() { if(DeArmedTestPassed) { PotVal = (analogRead(PotPin), 0, 1023, 0, 120); //Figure me out lcd.setCursor(0,0); delay(100); if(digitalRead(ArmPin) == HIGH && !HasLaunched) Armed = true; else Armed = false; if(digitalRead(SafePin) == HIGH) Safe = true; else Safe = false; if(digitalRead(LaunchPin) == HIGH) Launch = true; if(Armed) { lcd.setCursor(0,0); lcd.print("Status Armed "); delay(250); HasLaunched = false; } else { lcd.setCursor(0,0); lcd.print("Status Un-Armed"); delay(250); } if(Safe) { lcd.setCursor(10,1); lcd.print(" SAFE "); } else { lcd.setCursor(10,1); lcd.print(" "); } if(Armed && !Safe && !HasLaunched) { lcd.setCursor(9,1); lcd.print("LAUNCH"); delay(150); lcd.setCursor(9,1); lcd.print(" "); delay(150); } lcd.setCursor(0,1); lcd.print("T 00:00"); } else if(!DeArmedTestPassed) { lcd.setCursor(0,0); lcd.print("Please de-arm "); lcd.setCursor(0,1); lcd.print("device & reset"); } if(Armed && !Safe && !HasLaunched && Launch) { lcd.setCursor(8,1); lcd.print("LAUNCH!"); digitalWrite(13, HIGH); delay(1500); digitalWrite(13, LOW); lcd.setCursor(8,1); lcd.print(" "); Launch = false; Armed = false; HasLaunched = true; } }
So here is my problem. I will have a 10k pot. And as I turn it I want the time displayed(mock up at line 140) to increase to 2:00 when the pot is at max, and 00:05 at 0 pot. And once the system is unsafe and armed, you can initiate the launch. Once the launch is initiated it will count down and update the display to the new time every second. I have absolutely no idea how to set up the timer and display the decreasing time. I know I will have to use some form of a for loop. Bout it
Thanks Guys,
Austin