// Librerías utilizadas
#include "config.h"
#include <WiFi.h>
// Enlace a Adafruit: https://io.adafruit.com/Pablo_Caal_20538/dashboards/lab05
// Declaración de feeds
AdafruitIO_Feed *LED1 = io.feed("LED1");
AdafruitIO_Feed *LED2 = io.feed("LED2");
AdafruitIO_Feed *LED3 = io.feed("LED3");
AdafruitIO_Feed *POT1 = io.feed("POT1");
AdafruitIO_Feed *POT2 = io.feed("POT2");
// Declaracion PB
#define BUTTON_PIN1 23
#define BUTTON_PIN2 22
#define BUTTON_PIN3 21
// Declaracion POT
#define POT_PIN1 34
#define POT_PIN2 35
// Declaracion LED's
#define LED_PIN1 32
#define LED_PIN2 33
#define LED_PIN3 4
#define LED_PIN4 2
#define LED_PIN5 15
int PB1, PB2, PB3;
int POT_1, POT_2, LED_1, LED_2;
int VAL1, VAL2, VAL3, VAL4, VAL5;
void setup() {
Serial.begin(115200);
// Conexión a internet
Serial.print("Connecting to WiFi");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Connected!");
// Conexión a Adafruit
while(! Serial);
Serial.print("Connecting to Adafruit IO");
io.connect();
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.println(io.statusText());
// Configuración de puertos
pinMode(BUTTON_PIN1, INPUT_PULLUP);
pinMode(BUTTON_PIN2, INPUT_PULLUP);
pinMode(BUTTON_PIN3, INPUT_PULLUP);
pinMode(LED_PIN3, OUTPUT);
pinMode(LED_PIN4, OUTPUT);
pinMode(LED_PIN5, OUTPUT);
pinMode(POT_PIN1, INPUT);
pinMode(POT_PIN2, INPUT);
pinMode(LED_PIN1, OUTPUT);
pinMode(LED_PIN2, OUTPUT);
}
void loop() {
io.run();
// Primera parte, LEDs con PB //
// Declarando la lectura de los pines para PB //
PB1 = digitalRead(BUTTON_PIN1);
PB2 = digitalRead(BUTTON_PIN2);
PB3 = digitalRead(BUTTON_PIN3);
// Revisando estado PB 1 //
if (PB1 == 1){
digitalWrite(LED_PIN3, LOW);
VAL3 = 0;
}
else if (PB1 == 0){
digitalWrite(LED_PIN3, HIGH);
VAL3 = 1;
}
// Revisando estado PB 2 //
if (PB2 == 1){
digitalWrite(LED_PIN4, LOW);
VAL4 = 0;
}
else if (PB2 == 0){
digitalWrite(LED_PIN4, HIGH);
VAL4 = 1;
}
// Revisando estado PB 3 //
if (PB3 == 1){
digitalWrite(LED_PIN5, LOW);
VAL5 = 0;
}
else if (PB3 == 0){
digitalWrite(LED_PIN5, HIGH);
VAL5 = 1;
}
delay(10); // this speeds up the simulation
//---------------------------------------------------------//
// Segunda parte, LEDs con POT //
// Declarando la lectura de los pines para POT //
POT_1 = analogRead(POT_PIN1);
POT_2 = analogRead(POT_PIN2);
// Mapeando los valores del POT //
VAL1 = map(POT_1, 0, 4095, 0, 255);
VAL2 = map(POT_2, 0, 4095, 0, 255);
// Enviando valores a LEDs //
analogWrite(LED_PIN1, VAL1);
analogWrite(LED_PIN2, VAL2);
POT1->save(VAL1);
POT2->save(VAL2);
LED1->save(VAL3);
LED2->save(VAL4);
LED3->save(VAL5);
Serial.print("sending data...\n");
delay(5000);
}