@@ -37,6 +37,22 @@ void setup() {
37
37
// wait for serial monitor to open
38
38
while (! Serial);
39
39
40
+
41
+ #if defined(ARDUINO_ARCH_ESP32) // ESP32 pinMode
42
+ // assign rgb pins to channels
43
+ ledcAttachPin (RED_PIN, 1 );
44
+ ledcAttachPin (GREEN_PIN, 2 );
45
+ ledcAttachPin (BLUE_PIN, 3 );
46
+ // init. channels
47
+ ledcSetup (1 , 12000 , 8 );
48
+ ledcSetup (2 , 12000 , 8 );
49
+ ledcSetup (3 , 12000 , 8 );
50
+ #else
51
+ pinMode (RED_PIN, OUTPUT);
52
+ pinMode (GREEN_PIN, OUTPUT);
53
+ pinMode (BLUE_PIN, OUTPUT);
54
+ #endif
55
+
40
56
// connect to io.adafruit.com
41
57
Serial.print (" Connecting to Adafruit IO" );
42
58
io.connect ();
@@ -56,7 +72,6 @@ void setup() {
56
72
// we are connected
57
73
Serial.println ();
58
74
Serial.println (io.statusText ());
59
- color->get ();
60
75
61
76
// set analogWrite range for ESP8266
62
77
#ifdef ESP8266
@@ -92,8 +107,14 @@ void handleMessage(AdafruitIO_Data *data) {
92
107
Serial.println (data->value ());
93
108
94
109
// invert RGB values for common anode LEDs
95
- analogWrite (RED_PIN, 255 - data->toRed ());
96
- analogWrite (GREEN_PIN, 255 - data->toGreen ());
97
- analogWrite (BLUE_PIN, 255 - data->toBlue ());
98
-
110
+ #if defined(ARDUINO_ARCH_ESP32) // ESP32 analogWrite
111
+ ledcWrite (1 , 255 - data->toRed ());
112
+ ledcWrite (2 , 255 - data->toGreen ());
113
+ ledcWrite (3 , 255 - data->toBlue ());
114
+ #else
115
+ analogWrite (RED_PIN, 255 - data->toRed ());
116
+ analogWrite (GREEN_PIN, 255 - data->toGreen ());
117
+ analogWrite (BLUE_PIN, 255 - data->toBlue ());
118
+ #endif
119
+
99
120
}
0 commit comments