#include <WiFi.h>
#include "config.h"
#include "AdafruitIO.h"
AdafruitIO_Feed *LED1 = io.feed("LED1");
AdafruitIO_Feed *LED2 = io.feed("LED2");
AdafruitIO_Feed *LED3 = io.feed("LED3");
AdafruitIO_Feed *LED4 = io.feed("LED4");
AdafruitIO_Feed *LED5 = io.feed("LED5");
int valor1;
int valor2;
int valor3;
int valor4;
int valor5;
void setup() {
pinMode(23, OUTPUT);
pinMode(22, OUTPUT);
pinMode(21, OUTPUT);
pinMode(A10, OUTPUT);
pinMode(A13, OUTPUT);
Serial.begin(9600);
Serial.print("Connecting to WiFi");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Connected!");
// wait for serial monitor to open
// wait for serial monitor to open
while(! Serial);
Serial.print("Connecting to Adafruit IO");
// start MQTT connection to io.adafruit.com
io.connect();
// set up a message handler for the count feed.
// the handleMessage function (defined below)
// will be called whenever a message is
// received from adafruit io.
// wait for a connection
while(io.status() < WL_CONNECTED) {
Serial.print(".");
delay(500);
}
LED1->onMessage(handleMessage1);
LED2->onMessage(handleMessage2);
LED3->onMessage(handleMessage3);
LED4->onMessage(handleMessage4);
LED5->onMessage(handleMessage5);
// wait for an MQTT connection
// NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
// method to check on MQTT connection status specifically
while(io.mqttStatus() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
// Because Adafruit IO doesn't support the MQTT retain flag, we can use the
// get() function to ask IO to resend the last value for this feed to just
// this MQTT client after the io client is connected.
LED1->get();
LED2->get();
LED3->get();
LED4->get();
LED5->get();
// we are connected
Serial.println();
Serial.println(io.statusText());
}
void loop() {
// io.run(); is required for all sketches.
// it should always be present at the top of your loop
// function. it keeps the client connected to
// io.adafruit.com, and processes any incoming data.
io.run();
// Because this sketch isn't publishing, we don't need
// a delay() in the main program loop.
}
// this function is called whenever a 'counter' message
// is received from Adafruit IO. it was attached to
// the counter feed in the setup() function above.
void handleMessage1(AdafruitIO_Data *data) {
valor1 = (int)*(data -> value())-48;
digitalWrite(23,valor1);
}
void handleMessage2(AdafruitIO_Data *data) {
valor2 = (int)*(data -> value())-48;
digitalWrite(22,valor2);
}
void handleMessage3(AdafruitIO_Data *data) {
valor3 = (int)*(data -> value())-48;
digitalWrite(21,valor3);
}
void handleMessage4(AdafruitIO_Data *data) {
valor4 = (int)*(data -> value())-48;
analogWrite(A10,valor4);
}
void handleMessage5(AdafruitIO_Data *data) {
valor5 = (int)*(data -> value())-48;
digitalWrite(A13,valor5);
}