// =====================================================================================
// Sketch updated to https://forum.arduino.cc/t/push-button-switches-wont-work/860270/44
// =====================================================================================
// C++ code
//
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
const int MOTOR_CLOSE = 11; //"motor_forward" from other
const int MOTOR_OPEN = 10; //"motor_back" from other
const int RED_LIGHT = 14;
const int ORANGE_LIGHT = 15;
const int GREEN_LIGHT = 16;
const int BUTTON_OPEN = 9;
const int BUTTON_CLOSE = 8;
int buttonStateONE = 0;
int buttonStateTWO = 0;
int DOOR_STATUS=0; //Closed=0, Opening =1, Closing=2, Open=4
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(MOTOR_CLOSE, OUTPUT);
pinMode(MOTOR_OPEN, OUTPUT);
pinMode(RED_LIGHT, OUTPUT);
pinMode(ORANGE_LIGHT, OUTPUT);
pinMode(GREEN_LIGHT, OUTPUT);
pinMode(BUTTON_OPEN, INPUT);
pinMode(BUTTON_CLOSE, INPUT);
digitalWrite(RED_LIGHT, HIGH);
digitalWrite(ORANGE_LIGHT, HIGH);
digitalWrite(GREEN_LIGHT, HIGH);
lcd.setCursor(1, 0);
lcd.print("Comand&Control");
lcd.setCursor(0, 1);
lcd.print("Launch Bay Doors");
delay(3500); //CHANGE ME FOR FINAL TIMING 3-6s?!!!!
lcd.clear();
digitalWrite(RED_LIGHT, HIGH);
digitalWrite(ORANGE_LIGHT, LOW);
digitalWrite(GREEN_LIGHT, LOW);
lcd.setCursor(0, 0);
lcd.print("Launch Bay Doors");
lcd.setCursor(2, 1);
lcd.print("***CLOSED***");
delay(2500); //CHANGE ME FOR FINAL TIMING 2s?!!!!
}
void loop() {
while (DOOR_STATUS==0) {//while the door is closed
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Launch Bay Doors");
lcd.setCursor(2, 1);
lcd.print("***CLOSED***");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Launch Bay Doors");
lcd.setCursor(0, 1);
lcd.print("Press 1 to Open");
unsigned long start=millis();
while(digitalRead(BUTTON_OPEN==LOW)&&(millis()-start<300));
if (digitalRead(BUTTON_OPEN) == HIGH) {
digitalWrite(RED_LIGHT, LOW);
DOOR_STATUS=1; //change state to opening
}
}
if (DOOR_STATUS==1) { //the door is opening
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("***OPENING!***");
digitalWrite(MOTOR_OPEN, HIGH);
digitalWrite(RED_LIGHT, LOW);
digitalWrite(ORANGE_LIGHT, HIGH);
digitalWrite(GREEN_LIGHT, LOW);
delay(4000);//"door" takes 4s to open
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Launch Bay Doors");
lcd.setCursor(3, 1);
lcd.print("***OPEN***");
digitalWrite(MOTOR_OPEN, LOW);
digitalWrite(RED_LIGHT, LOW);
digitalWrite(ORANGE_LIGHT, LOW);
digitalWrite(GREEN_LIGHT, HIGH);
delay(2000);
DOOR_STATUS=4; //the door is open
}
while (DOOR_STATUS==4) { //while the door is fully open
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Launch Bay Doors");
lcd.setCursor(3, 1);
lcd.print("***OPEN***");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("* STARBUCK IS *");
lcd.setCursor(0, 1);
lcd.print("CLEAR FOR LAUNCH");
delay(2500);
lcd.clear();
lcd.setCursor(3, 1);
lcd.print("*GO GO GO*");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Launch Bay Doors");
lcd.setCursor(0, 1);
lcd.print("Press 2 to Close");
unsigned long start=millis();
while(digitalRead(BUTTON_CLOSE==LOW)&&(millis()-start<300));
if(digitalRead(BUTTON_CLOSE)==HIGH){
DOOR_STATUS=3; //the door is closing
//add additional LED on/off here
}
}
if (DOOR_STATUS==3) { //if the door is closing
lcd.clear();
lcd.setCursor(1,0);
lcd.print("***CLOSING!***");
digitalWrite(MOTOR_CLOSE, HIGH);
digitalWrite(RED_LIGHT, LOW);
digitalWrite(ORANGE_LIGHT, HIGH);
digitalWrite(GREEN_LIGHT, LOW);
delay(4000);//"door" takes 4s to close.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Launch Bay Doors");
lcd.setCursor(3, 1);
lcd.print("**CLOSED**");
digitalWrite(MOTOR_CLOSE, LOW);
digitalWrite(RED_LIGHT, HIGH);
digitalWrite(ORANGE_LIGHT, LOW);
digitalWrite(GREEN_LIGHT, LOW);
delay(1500);
DOOR_STATUS=0; //the door is closed
}
}