#include <ThingESP.h>
#include <WiFi.h>
// #include <ESP32Servo.h>
#include <LiquidCrystal.h>
// definiciones del servoculo y la pantallita pendeja
LiquidCrystal LCD (22, 23, 2, 4, 5, 15);
// Servo S1;
// DEFINICIÓN DEL PUTO SERVER THINGESP
ThingESP32 tg("YIMI","SYNCHYDROTI", "WTANK_CONTROLLER");
long ULTRASONICO(int TX, int RX){
// retorno de la lectura del maldito ultrasónico y disparo de bolas
pinMode(TX, OUTPUT);
digitalWrite(TX, LOW);
delayMicroseconds(2);
digitalWrite(TX, HIGH);
delayMicroseconds(10);
digitalWrite(TX, LOW);
pinMode(RX, INPUT);
return pulseIn(RX, HIGH);
}
// pines para los actuadores de mierda
int pinTX = 16;
int pinRX = 17;
// int pinSERVO = 18;
// pines para los leds de mierda asquerosos
int pinLED1 = 26;
int pinLED2 = 25;
int pinLED3 = 33;
//Variables de mierda
float d = 0;
void setup(){
//Iniciar server ThingESP del culo
Serial.begin(115200);
tg.SetWiFi("Wokwi-GUEST", "");
tg.initDevice();
// defininiciones de leds como salidas (escritura pedorra)
pinMode(pinLED1, OUTPUT);
pinMode(pinLED2, OUTPUT);
pinMode(pinLED3, OUTPUT);
// inicialización del servo de cagada en 0 grados y 500-2500
/* S1.attach(pinSERVO, 500, 2500);
S1.write(0);
*/
//Iniciar la pantallita hinchapelotas
LCD.clear();
LCD.begin(20,4);
}
String HandleResponse(String M){
if(M == "ultra basura"){
d = 0.01715*ULTRASONICO(pinTX, pinRX);
delay(100);
String dSt = String (d,3);
delay(1000);
LCD.setCursor(0,3);
LCD.print("");
delay(1000);
LCD.setCursor(0,3);
LCD.print("DISTANCIA= " + dSt);
return "TU MIERDA DE DISTANCIA ES: " + dSt;
}
/* else if (M == "enciende servo"){
S1.write(90);
delay(1000);
LCD.setCursor(0,2);
LCD.print("");
delay(1000);
LCD.setCursor(0,2);
LCD.print("SERVO ENCENDIDO");
return "GIRABOLAS ENCENDIDO";
}
else if (M == "apaga servo"){
S1.write(0);
delay(1000);
LCD.setCursor(0,2);
LCD.print("");
delay(1000);
LCD.setCursor(0,2);
LCD.print("SERVO APAGADO");
return "GIRABOLAS APGADO";
} */
else if (M == "lucecita 1 on"){
digitalWrite(pinLED1, HIGH);
delay(1000);
LCD.setCursor(0,0);
LCD.print("");
delay(1000);
LCD.setCursor(0,0);
LCD.print("LED1_ON");
return "tu pinche lucecita se ha encendido 1";
}
else if (M == "lucecita 2 on"){
digitalWrite(pinLED2, HIGH);
delay(1000);
LCD.setCursor(9,0);
LCD.print("");
delay(1000);
LCD.setCursor(9,0);
LCD.print("LED2_ON");
return "tu pinche lucecita se ha encendido 2";
}
else if (M == "lucecita 3 on"){
digitalWrite(pinLED3, HIGH);
delay(1000);
LCD.setCursor(0,1);
LCD.print("");
delay(1000);
LCD.setCursor(0,1);
LCD.print("LED3_ON");
return "tu pinche lucecita se ha encendido 3";
}
else if (M == "lucecita 1 off"){
digitalWrite(pinLED1, LOW);
delay(1000);
LCD.setCursor(0,0);
LCD.print("");
delay(1000);
LCD.setCursor(0,0);
LCD.print("LED1_OFF");
return "tu pinche lucecita se ha apagado 1";
}
else if (M == "lucecita 2 off"){
digitalWrite(pinLED2, LOW);
delay(1000);
LCD.setCursor(9,0);
LCD.print("");
delay(1000);
LCD.setCursor(9,0);
LCD.print("LED2_OFF");
return "tu pinche lucecita se ha apagado 2";
}
else if (M == "lucecita 3 off"){
digitalWrite(pinLED3, LOW);
delay(1000);
LCD.setCursor(0,1);
LCD.print("");
delay(1000);
LCD.setCursor(0,1);
LCD.print("LED3_OFF");
return "tu pinche lucecita se ha apagado 3";
}
else return "ESCRIBE BIEN MALNACIDOOOOOO";
}
void loop(){
tg.Handle();
}