#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
int gaugepin = 0;
int pressure;
int JumpThreshold = 800;
int JumpStart = 0;
int JumpEnd = 0;
int JumpState = 0; // 0 = not on plate, 1 = on plate and ready, 2 = in midair, 3 = landed
float HangTime = 0;
float JumpHeight = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Let's jump");
lcd.setCursor(0, 1);
lcd.print("bitches!");
delay(2000);
lcd.clear();
}
void loop() {
// put your main code here, to run repeatedly:
// Second counter
//lcd.setCursor(0, 1);
//lcd.print("Count: ");
//lcd.setCursor(7,1);
//lcd.print(millis() / 1000);
pressure = analogRead(gaugepin);
Serial.println(pressure);
if (JumpState == 0 && pressure < JumpThreshold) {
lcd.setCursor(0,0);
lcd.print("Step onto plate");
}
if (JumpState == 0 && pressure > JumpThreshold) {
JumpState = 1;
lcd.setCursor(0,0);
lcd.print("Prepare to jump");
delay(2000);
}
if (JumpState == 1) {
lcd.setCursor(0,0);
lcd.print("Jump when ready");
}
if (JumpState == 1 && pressure < JumpThreshold) {
JumpStart = millis();
JumpState = 2;
lcd.setCursor(0,0);
lcd.print("Jumping... ");
}
if (JumpState == 2 && pressure > JumpThreshold) {
JumpEnd = millis();
JumpState = 3;
HangTime = (float)(JumpEnd - JumpStart) / 1000;
JumpHeight = (float)((9.81 *(HangTime*HangTime)) / 8) * 100;
lcd.setCursor(0,0);
lcd.print("Landed! ");
delay(3000);
}
if (JumpState == 3) {
lcd.setCursor(0,0);
lcd.print("Hangtime=");
lcd.print(HangTime);
lcd.print ("s");
lcd.setCursor(0,1);
lcd.print("Height=");
lcd.print(JumpHeight);
lcd.print ("cm");
delay(5000);
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Last=");
lcd.print(JumpHeight);
lcd.print ("cm ");
JumpState = 0;
}
}