// This is the source code associated with Robot Propulsion in a Microgravity by Parth Chaudhry #include LiquidCrystal_I2C lcd(0x27,16,2); const int forward = 2; const int backward = 4; const int extensionTime = 1700; const int SECONDS_TO_WAIT = 20; const int INITIAL_WAIT = 10; void setup() { // put your setup code here, to run once: // Initialize the LCD lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); // Initialize the pins for the linear actuator control pinMode(forward,OUTPUT); pinMode(backward,OUTPUT); } int PotentiometerReading() { int reading = analogRead(A0); if(reading < 50) { return 0; } else if(reading < 250) { return 1; } else if(reading < 500) { return 2; } else if(reading < 750) { return 3; } else if(reading < 1000) { return 4; } else { return 50; } } void loop() { // put your main code here, to run repeatedly: int impulseTimeIncrement = 100; int totalTime = 0; int waitTime = 0; int counter = 0; int potMeterReading = 0; // initial wait counter = 0; while(counter < INITIAL_WAIT) { lcd.clear(); lcd.setCursor(0,0); lcd.print("Initial Wait."); lcd.setCursor(0,1); lcd.print("Time left(s):"); lcd.setCursor(13,1); lcd.print(INITIAL_WAIT - counter); counter++; // Sleep 1 second delay(1000); } potMeterReading = PotentiometerReading(); if(potMeterReading != 0) { totalTime = extensionTime + impulseTimeIncrement*potMeterReading; lcd.clear(); lcd.setCursor(0,0); lcd.print("Starting actuator"); lcd.setCursor(0,1); lcd.print("impulse time:"); lcd.setCursor(12,1); lcd.print(totalTime - extensionTime); digitalWrite(forward,HIGH); digitalWrite(backward,LOW); delay(totalTime); } else { lcd.clear(); lcd.setCursor(0,0); lcd.print("Pot Meter = 0"); } digitalWrite(forward,LOW); digitalWrite(backward,HIGH); // Wait for the actuator to retract totalTime = extensionTime; delay(totalTime); counter = 0; while(counter < SECONDS_TO_WAIT) { lcd.clear(); lcd.setCursor(0,0); lcd.print("Waiting to Check"); lcd.setCursor(0,1); lcd.print("Time left(s):"); lcd.setCursor(13,1); lcd.print(SECONDS_TO_WAIT - counter); counter++; // Sleep 1 second delay(1000); } }