Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- int RelayPin = 6; //Relay!
- int delayTime = 5; //Seconds to hold the relay open
- int buttonState = 0; //The state of the button (1, 0)
- int buttonPin = 7; //Pin of the button. Make sure to connect the other end to GND, not 5V
- int countdown = 0; //Don't edit this, edit countVal instead!
- int countVal = 15; //Time (in seconds) you have to run.
- int contPin = 8; //The Pin for the continutity sensor
- int contState = 0; //State of continutity
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //LCD Config Pins
- void setup()
- {
- //LCD Columns,Rows
- lcd.begin(16, 2);
- lcd.setCursor(0, 0);
- lcd.print("Welcome to");
- lcd.setCursor(0, 1);
- lcd.print("RocketLaunch 4.4");
- delay(1750);
- pinMode(RelayPin, OUTPUT); //Set the relay as an output
- pinMode(buttonPin, INPUT); //Self-Explanitory
- pinMode(contPin, INPUT);
- digitalWrite(buttonPin, HIGH); //Pull-Up Resistor
- digitalWrite(contPin, HIGH); //Pull-Up Resistor
- lcd.clear();
- }
- void loop() {
- top:
- contState = digitalRead(contPin);
- if(contState == LOW) {
- lcd.clear();
- lcd.print("Ready to Launch!");
- lcd.setCursor(0,1);
- lcd.print("Press button...");
- delay(100); //Quick anti-flicker delay
- countdown = countVal;
- buttonState = digitalRead(buttonPin);
- if(buttonState == LOW) {
- lcd.clear();
- lcd.print("Launching in:");
- for(countdown > 0; countdown--;) {
- contState = digitalRead(contPin);
- lcd.setCursor(0,1);
- lcd.print(countdown + 1);
- lcd.print(' ');
- lcd.print("second(s) ");
- delay(1000);
- if(contState == HIGH) {
- onDisconnect();
- }
- }
- lcd.clear();
- lcd.print("Igniting Engine");
- digitalWrite(RelayPin, HIGH);
- delay(1000*delayTime);
- digitalWrite(RelayPin, LOW);
- contState = digitalRead(contPin);
- if(contState == LOW) {
- lcd.clear();
- lcd.print("Warning: Rocket");
- lcd.setCursor(0,1);
- lcd.print("not ignited! ");
- delay(2500);
- lcd.clear();
- }
- else {
- lcd.clear();
- lcd.print("WHOOOOSH! ");
- delay(2500);
- }
- }
- }
- else {
- lcd.clear();
- lcd.print("ERROR: Ignitor");
- lcd.setCursor(0,1);
- lcd.print("not plugged in!");
- delay(1000);
- }
- }
- void onDisconnect() {
- lcd.clear();
- lcd.print("ERROR: Ignitor");
- lcd.setCursor(0,1);
- lcd.print("was unplugged! ");
- delay(5000);
- goto top;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement