Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
#include <ESP32Servo.h>
#include <analogWrite.h>
Servo myservo;
/*
A simple web server that lets you blink an LED via the web.
This sketch will print the IP address of your WiFi Shield (once connected)
to the Serial monitor. From there, you can open that address in a web browser
Circuit:
by Tom Igoe
*/
#include <WiFi.h>
WiFiServer server(80);
class DCMotor {
public:
void Pinout(int in1, int in2){ // Pinout é o método para a declaração dos pinos que vão
controlar o objeto motor
pin1 = in1;
pin2 = in2;
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
void Speed(int in1){ // Speed é o método que irá ser responsável por salvar a velocidade de
atuação do motor
spd = in1;
void Forward(){ // Forward é o método para fazer o motor girar para frente
analogWrite(pin1, spd);
digitalWrite(pin2, LOW);
void Backward(){ // Backward é o método para fazer o motor girar para trás
digitalWrite(pin1, LOW);
analogWrite(pin2, spd);
}
void Stop(){ // Stop é o metodo para fazer o motor ficar parado.
digitalWrite(pin1, LOW);
digitalWrite(pin2, LOW);
};
DCMotor Motor1, Motor2; // Criação de dois objetos motores, já que usaremos dois
motores, e eles já estão prontos para receber os comandos já configurados acima.
int i;
void setup() {
Motor1.Pinout(22,21); // Seleção dos pinos que cada motor usará, como descrito na classe.
Motor2.Pinout(13,14);
Serial.begin(115200);
pinMode(15, OUTPUT);
pinMode(4, OUTPUT);
pinMode(2, OUTPUT);
pinMode(18, OUTPUT);
myservo.attach(servo);
myservo.write(180);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
delay(500);
Serial.print(".");
Serial.println("");
Serial.println("WiFi connected.");
Serial.println(WiFi.localIP());
server.begin();
int value = 0;
void loop(){
Motor2.Speed(200);
String currentLine = ""; // make a String to hold incoming data from the client
// if the current line is blank, you got two newline characters in a row.
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("Content-type:text/html");
client.println();
client.print("<html>");
client.print("<body>");
client.print("<h3>A1</h3>");
client.print("<h3>A2</h3>");
client.print("<h3>A3</h3>");
client.print("<h3>A4</h3>");
client.print("<h3>A5</h3>");
client.print("<h3>Roda Gigante</h3>");
client.print("<a href=\"/rg/H\"><button class=\"RodaLiga\">Ligar</button></a>");
client.print("<h3>Chapéu Mexicano</h3>");
client.print("</body>");
client.println();
break;
currentLine = "";
} else if (c != '\r') { // if you got anything else but a carriage return character,
// Check to see if the client request was "GET /H" or "GET /L":
if (currentLine.endsWith("GET /a1/H")) {
myservo.write(10);
delay(10000);
myservo.write(180);
if (currentLine.endsWith("GET /a1/L")) {
myservo.write(10);
delay(10000);
myservo.write(180);
if (currentLine.endsWith("GET /a2/H")) {
digitalWrite(2, HIGH); // GET /H turns the LED on
myservo.write(10);
delay(10000);
myservo.write(180);
if (currentLine.endsWith("GET /a2/L")) {
myservo.write(10);
delay(10000);
myservo.write(180);
if (currentLine.endsWith("GET /a3/H")) {
myservo.write(10);
delay(10000);
myservo.write(180);
if (currentLine.endsWith("GET /a3/L")) {
myservo.write(10);
delay(10000);
myservo.write(180);
if (currentLine.endsWith("GET /a4/H")) {
myservo.write(10);
delay(10000);
myservo.write(180);
if (currentLine.endsWith("GET /a4/L")) {
delay(10000);
myservo.write(180);
if (currentLine.endsWith("GET /a5/H")) {
myservo.write(10);
delay(10000);
myservo.write(180);
if (currentLine.endsWith("GET /a5/L")) {
myservo.write(10);
delay(10000);
myservo.write(180);
if (currentLine.endsWith("GET /rg/H")) {
if (currentLine.endsWith("GET /rg/L")) {
if (currentLine.endsWith("GET /cm/H")) {
if (currentLine.endsWith("GET /cm/L")) {
Serial.println("Client Disconnected.");