From d402b752b532ae915277e8adcc1aceec6944bbf9 Mon Sep 17 00:00:00 2001 From: Eric Yu Date: Wed, 8 Jun 2022 11:38:43 -0700 Subject: [PATCH] Update main.cpp --- ReadAnalog/src/main.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ReadAnalog/src/main.cpp b/ReadAnalog/src/main.cpp index 6430b18..7ffbfb0 100644 --- a/ReadAnalog/src/main.cpp +++ b/ReadAnalog/src/main.cpp @@ -1,5 +1,19 @@ #include +#if defined(ESP32) +#define A0 (36) +#define A1 (39) +#define A2 (34) +#define A3 (35) +#define A4 (32) +#define A5 (33) +#endif +// define the divident of sizeof()'s return value +#if defined(ESP32) +#define SIZE_DIV 4 // size / 4 for 12-bit device +#else +#define SIZE_DIV 2 // size / 2 for 10-bit device +#endif #define WAIT_TIME 1000UL int pins[] = {A0, A1, A2, A3, A4, A5}; @@ -14,9 +28,9 @@ void setup() { void loop() { if (millis() - currTime >= WAIT_TIME) { // non-blocking time delay Serial.print("["); - for (i = 0; i < sizeof(pins)/2; i++) { + for (i = 0; i < sizeof(pins)/SIZE_DIV; i++) { Serial.print(analogRead(pins[i])); - if (i != sizeof(pins)/2 - 1) { + if (i != sizeof(pins)/SIZE_DIV - 1) { Serial.print(", "); } }