da

08 December 2018

Views: 70

#include <AdafruitIO.h>
#include "config.h"
#define RED_PIN 15
#define GREEN_PIN 2
#define BLUE_PIN 13

AdafruitIO_Feed *colour = io.feed("COLOUR_RHB");

void setup() {
Serial.begin(115200);
while(! Serial);
Serial.print("Connecting to Adafruit IO");
io.connect();
colour->onMessage(handleMessage);

while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.println(io.statusText());

#ifdef ESP8266
analogWriteRange(255);
#endif
}

void loop() { io.run(); }

void handleMessage(AdafruitIO_Data *data) {

Serial.println("Received:");
Serial.print(" - R: ");
Serial.println(data->toRed());
Serial.print(" - G: ");
Serial.println(data->toGreen());
Serial.print(" - B: ");
Serial.println(data->toBlue());
Serial.print(" - HEX: ");
Serial.println(data->value());

analogWrite(RED_PIN, data->toRed());
analogWrite(GREEN_PIN, data->toGreen());
analogWrite(BLUE_PIN, data->toBlue());

}

Share