#define BLYNK_TEMPLATE_ID "TMPL6It8o_tWh"
#define BLYNK_TEMPLATE_NAME "Akasena Launcher"
#define BLYNK_AUTH_TOKEN "1eWLABbdvtTsmsM8Z4ONepNGgnIMLwhw"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
// WiFi Wokwi
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// ===== PIN =====
#define STEP_PIN 26
#define DIR_PIN 27
#define EN_PIN 25
#define STEPS_PER_REV 200
bool stepperActive = false;
int stepCounter = 0;
unsigned long prevMicros = 0;
const int stepDelay = 1500;
// ================= SETUP =================
void setup() {
Serial.begin(115200);
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
pinMode(EN_PIN, OUTPUT);
digitalWrite(EN_PIN, LOW);
digitalWrite(STEP_PIN, LOW);
digitalWrite(DIR_PIN, LOW);
// --- CONNECT WIFI MANUAL ---
WiFi.begin(ssid, pass);
Serial.print("Connecting WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi Connected");
// --- FORCE REGION SGP1 ---
Blynk.config(BLYNK_AUTH_TOKEN, "sgp1.blynk.cloud", 80);
if (Blynk.connect()) {
Serial.println("Blynk Connected");
} else {
Serial.println("Blynk Failed");
}
}
// ================= LOOP =================
void loop() {
Blynk.run();
runStepper();
}
// ================= STEPPER ENGINE =================
void runStepper() {
if (!stepperActive) return;
unsigned long now = micros();
if (now - prevMicros >= stepDelay) {
prevMicros = now;
digitalWrite(STEP_PIN, !digitalRead(STEP_PIN));
if (digitalRead(STEP_PIN) == LOW) {
stepCounter++;
if (stepCounter >= STEPS_PER_REV) {
stepperActive = false;
stepCounter = 0;
Serial.println("360 DEGREE COMPLETE");
}
}
}
}
// ================= BLYNK CONTROL =================
BLYNK_WRITE(V1) {
int state = param.asInt();
digitalWrite(DIR_PIN, state == 1 ? HIGH : LOW);
stepperActive = true;
stepCounter = 0;
Serial.println(state == 1 ? "WINCH TARIK 360" : "WINCH LONGGAR 360");
}