Advertisement
waterlubber

Error with goto:

Dec 2nd, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.51 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. int RelayPin = 6; //Relay!
  3. int delayTime = 5; //Seconds to hold the relay open
  4. int buttonState = 0; //The state of the button (1, 0)
  5. int buttonPin = 7; //Pin of the button. Make sure to connect the other end to GND, not 5V
  6. int countdown = 0; //Don't edit this, edit countVal instead!
  7. int countVal = 15; //Time (in seconds) you have to run.
  8. int contPin = 8; //The Pin for the continutity sensor
  9. int contState = 0; //State of continutity
  10. LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //LCD Config Pins
  11. void setup()
  12. {
  13.   //LCD Columns,Rows
  14.   lcd.begin(16, 2);
  15.   lcd.setCursor(0, 0);
  16.   lcd.print("Welcome to");
  17.   lcd.setCursor(0, 1);
  18.   lcd.print("RocketLaunch 4.4");
  19.   delay(1750);
  20.   pinMode(RelayPin, OUTPUT); //Set the relay as an output
  21.   pinMode(buttonPin, INPUT); //Self-Explanitory
  22.   pinMode(contPin, INPUT);
  23.   digitalWrite(buttonPin, HIGH); //Pull-Up Resistor
  24.   digitalWrite(contPin, HIGH); //Pull-Up Resistor
  25.   lcd.clear();
  26. }
  27.  
  28. void loop() {
  29.   top:
  30.   contState = digitalRead(contPin);
  31.   if(contState == LOW) {
  32.     lcd.clear();
  33.     lcd.print("Ready to Launch!");
  34.     lcd.setCursor(0,1);
  35.     lcd.print("Press button...");
  36.     delay(100); //Quick anti-flicker delay
  37.     countdown = countVal;
  38.     buttonState = digitalRead(buttonPin);
  39.     if(buttonState == LOW) {
  40.       lcd.clear();
  41.       lcd.print("Launching in:");
  42.         for(countdown > 0; countdown--;) {
  43.           contState = digitalRead(contPin);
  44.           lcd.setCursor(0,1);
  45.           lcd.print(countdown + 1);
  46.           lcd.print(' ');
  47.           lcd.print("second(s)  ");
  48.           delay(1000);
  49.           if(contState == HIGH) {
  50.             onDisconnect();
  51.           }
  52.       }
  53.       lcd.clear();
  54.       lcd.print("Igniting Engine");
  55.       digitalWrite(RelayPin, HIGH);
  56.       delay(1000*delayTime);
  57.       digitalWrite(RelayPin, LOW);
  58.       contState = digitalRead(contPin);
  59.       if(contState == LOW) {
  60.         lcd.clear();
  61.         lcd.print("Warning: Rocket");
  62.         lcd.setCursor(0,1);
  63.         lcd.print("not ignited!   ");
  64.         delay(2500);
  65.         lcd.clear();
  66.       }
  67.       else {
  68.         lcd.clear();
  69.         lcd.print("WHOOOOSH!       ");
  70.         delay(2500);
  71.       }      
  72.  
  73.     }
  74.   }  
  75.   else {
  76.     lcd.clear();
  77.     lcd.print("ERROR: Ignitor");
  78.     lcd.setCursor(0,1);
  79.     lcd.print("not plugged in!");
  80.     delay(1000);  
  81.   }
  82. }
  83. void onDisconnect() {
  84.   lcd.clear();
  85.   lcd.print("ERROR: Ignitor");
  86.   lcd.setCursor(0,1);
  87.   lcd.print("was unplugged!  ");
  88.   delay(5000);
  89.   goto top;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement