Skip to content

Commit ac952a4

Browse files
authored
Merge pull request #29 from brentru/fix-ex-09
fix for esp32's lack of analogwrite implementation
2 parents 835b840 + e12b6e4 commit ac952a4

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

examples/adafruitio_09_analog_out/adafruitio_09_analog_out.ino

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ AdafruitIO_Feed *analog = io.feed("analog");
2828

2929
void 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
}

0 commit comments

Comments
 (0)