Paso 4: Código de Arduino
Para descargar el código de nuestro módulo con éxito, primero necesitamos tierra GPIOs 0 y 15, y GPIO2 alta con 3.3V. Una vez que la instalación esté lista, seleccionamos "genérico ESP8266 módulo" como nuestro Consejo y haga clic en el botón "subir".
#include #include const char *ssid = "Zumo Robot"; const char *password = "12345678"; ESP8266WebServer server(80); const int motor1 = 2; const int motor2 = 15; const int motorA = 0; const int motorB = 4; int motor_speed; void setup() { delay(1000); Serial.begin(115200); pinMode(motor1, OUTPUT);> pinMode(motor2, OUTPUT); pinMode(motorA, OUTPUT); pinMode(motorB, OUTPUT); WiFi.softAP(ssid, password); server.on("/", []() { String url = server.arg("pin"); String state = url.substring(0,3); String value = url.substring(3); motor_speed = value.toInt(); if (state == "ONA"){ analogWrite(motor1, 0); analogWrite(motor2, motor_speed); analogWrite(motorA, 0); analogWrite(motorB, motor_speed); } else if (url == "OFFA"){ analogWrite(motor1, 0); analogWrite(motor2, 0); analogWrite(motorA, 0); analogWrite(motorB, 0); } else if (state == "ONB"){ analogWrite(motor1, motor_speed); analogWrite(motor2, 0); analogWrite(motorA, motor_speed); analogWrite(motorB, 0); } else if (url == "OFFB"){ analogWrite(motor1, 0); analogWrite(motor2, 0); analogWrite(motorA, 0); analogWrite(motorB, 0); } else if (state == "ONC"){ analogWrite(motor1, 0); analogWrite(motor2, motor_speed); analogWrite(motorA, motor_speed); analogWrite(motorB, 0); } else if (url == "OFFC"){ analogWrite(motor1, 0); analogWrite(motor2, 0); analogWrite(motorA, 0); analogWrite(motorB, 0); } else if (state == "OND"){ analogWrite(motor1, motor_speed); analogWrite(motor2, 0); analogWrite(motorA, 0 ); analogWrite(motorB, motor_speed); } else if (url == "OFFD"){ analogWrite(motor1, 0); analogWrite(motor2, 0); analogWrite(motorA, 0); analogWrite(motorB, 0); } }); server.begin(); } void loop() { server.handleClient(); }