File tree Expand file tree Collapse file tree
examples/adafruitio_09_analog_out Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,6 +28,15 @@ AdafruitIO_Feed *analog = io.feed("analog");
2828
2929void setup () {
3030
31+ // set up led pin as an analog output
32+ #if defined(ARDUINO_ARCH_ESP32)
33+ // ESP32 pinMode()
34+ ledcAttachPin (LED_PIN, 1 );
35+ ledcSetup (1 , 1200 , 8 );
36+ #else
37+ pinMode (LED_PIN, OUTPUT);
38+ #endif
39+
3140 // start the serial connection
3241 Serial.begin (115200 );
3342
@@ -53,7 +62,6 @@ void setup() {
5362 // we are connected
5463 Serial.println ();
5564 Serial.println (io.statusText ());
56- analog->get ();
5765
5866}
5967
@@ -77,6 +85,13 @@ void handleMessage(AdafruitIO_Data *data) {
7785
7886 Serial.print (" received <- " );
7987 Serial.println (reading);
80- analogWrite (LED_PIN, reading);
88+
89+
90+ // write the current 'reading' to the led
91+ #if defined(ARDUINO_ARCH_ESP32)
92+ ledcWrite (1 , reading); // ESP32 analogWrite()
93+ #else
94+ analogWrite (LED_PIN, reading);
95+ #endif
8196
8297}
You can’t perform that action at this time.
0 commit comments