Update main.cpp

This commit is contained in:
Eric Yu 2022-06-08 11:38:43 -07:00 committed by GitHub
parent f562b2a387
commit d402b752b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 2 deletions

View File

@ -1,5 +1,19 @@
#include <Arduino.h> #include <Arduino.h>
#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 #define WAIT_TIME 1000UL
int pins[] = {A0, A1, A2, A3, A4, A5}; int pins[] = {A0, A1, A2, A3, A4, A5};
@ -14,9 +28,9 @@ void setup() {
void loop() { void loop() {
if (millis() - currTime >= WAIT_TIME) { // non-blocking time delay if (millis() - currTime >= WAIT_TIME) { // non-blocking time delay
Serial.print("["); Serial.print("[");
for (i = 0; i < sizeof(pins)/2; i++) { for (i = 0; i < sizeof(pins)/SIZE_DIV; i++) {
Serial.print(analogRead(pins[i])); Serial.print(analogRead(pins[i]));
if (i != sizeof(pins)/2 - 1) { if (i != sizeof(pins)/SIZE_DIV - 1) {
Serial.print(", "); Serial.print(", ");
} }
} }