/* Hello Wokwi! */
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int jump_state = 0; //0 = about to jump, 1 = jumping, 2 = post-jump
int threshold = 500;
long int jump_start = 0;
long int jump_end = 0;
long int jump_time = 0;
long int display_delay = 5000; //time to display jump in milliseconds
void setup() {
Serial.begin(115200); // Any baud rate should work
//Serial.println("Hello Arduino\n");
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Hello, Wokwi!");
lcd.setCursor(0, 0);
lcd.print("Time: ");
}
void loop() {
//delay(100);
//Serial.println("\n");
lcd.setCursor(6, 0);
lcd.print(millis() / 1000);
lcd.print(" ");
lcd.print(val);
lcd.print(" ");
lcd.setCursor(15, 0);
lcd.print(jump_state);
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
Serial.println(val);
if(jump_state == 0) {
//Serial.println("Jump state = 0");
lcd.setCursor(0, 1);
lcd.print("Ready to record");
if (val>threshold) {
jump_state = 1;
jump_start = millis();
lcd.setCursor(0, 1);
lcd.print(" ");
}
} else if (jump_state == 1) {
//Serial.println("Jump state = 1");
lcd.setCursor(0, 1);
lcd.print("Jumping!");
if (val<threshold) {
//Serial.println(" val_low");
jump_state = 2;
jump_end = millis();
jump_time = jump_end-jump_start;
}
} else if (jump_state == 2) {
//Serial.println("Jump state = 1");
lcd.setCursor(0, 1);
lcd.print("Jump = ");
lcd.print(jump_time);
if (millis() - jump_end > display_delay){
jump_state = 0;
}
}
//Serial.println(" ");
//Serial.println(jump_state);
}