#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL6f0mmupgn"
#define BLYNK_TEMPLATE_NAME "LED3"
#define BLYNK_AUTH_TOKEN "pwn1WnjRszJRsNE0KYYtxORMM-o2TcU8"
#define GRAVITY 9.8
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <LiquidCrystal.h>
#include <ESP32Servo.h>
#include <math.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// RS E D4 D5 R6 D7
LiquidCrystal lcd(19, 23, 18, 17, 16, 15);
double distance_blynk = 0.0;
double height_blynk = 0.0;
BlynkTimer timer;
Servo motor1;
BLYNK_WRITE(V5) {
distance_blynk = param.asDouble();
}
BLYNK_WRITE(V6) {
height_blynk = param.asDouble();
}
void calculateParameters(double distance, double height, double* angle, double* velocity) {
distance = fabs(distance);
height = fabs(height);
*angle = atan2(height, distance);
*velocity = sqrt((distance * GRAVITY) / sin(2 * *angle));
}
void setup() {
Serial.begin(115200);
lcd.begin(16, 2);
motor1.attach(27);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, []() {
// Periodic tasks
});
}
void loop() {
Blynk.run();
timer.run();
double angle, velocity;
calculateParameters(distance_blynk, height_blynk, &angle, &velocity);
Serial.println("\nProjectile Parameters:");
Serial.println("distance: " + String(distance_blynk) + " m");
Serial.println("height: " + String(height_blynk) + " m");
Serial.println("Launch Angle: " + String(angle * 180.0 / M_PI) + " degrees");
Serial.println("Initial Velocity (Force): " + String(velocity) + " m/s");
Serial.print("------------------------");
lcd.clear();
lcd.setCursor(0, 0);
// lcd.print("Launch Angle: ");
lcd.print(angle * 180.0 / M_PI);
lcd.print(" degrees");
lcd.setCursor(0, 1);
// lcd.print("Initial Velocity: ");
lcd.print(velocity);
lcd.print(" m/s");
motor1.write(angle * 180.0 / M_PI);
delay(1000);
}