Update espVoltmeter.ino
This commit is contained in:
parent
23cf5d8714
commit
c8dcddd2b5
|
@ -1,57 +1,34 @@
|
||||||
// manually define all the An ports on ESP32 board
|
// manually define all the An ports on ESP32 board
|
||||||
#if defined(ESP32)
|
#define A0 (36)
|
||||||
#define A0 (36)
|
#define A1 (39)
|
||||||
#define A1 (39)
|
#define A2 (34)
|
||||||
#define A2 (34)
|
#define A3 (35)
|
||||||
#define A3 (35)
|
#define A4 (32)
|
||||||
#define A4 (32)
|
#define A5 (33)
|
||||||
#define A5 (33)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// define the divident of sizeof()'s return value
|
// define the divident of sizeof()'s return value, to the correct length of our list
|
||||||
#if defined(ESP32)
|
|
||||||
#define SIZE_DIV 4 // for esp32, the resolution is doubled than the usual arduino board, so we double the factor, too
|
#define SIZE_DIV 4 // for esp32, the resolution is doubled than the usual arduino board, so we double the factor, too
|
||||||
#else
|
#define WAIT_TIME 1000UL
|
||||||
#define SIZE_DIV 2
|
int pins[] = { A0, A1, A2, A3, A4, A5 };
|
||||||
#endif
|
|
||||||
#define WAIT_TIME 1000UL
|
|
||||||
#define SENSOR1 36
|
|
||||||
// FILE *f = fopen("file.txt", "w");
|
|
||||||
int pins[] = {A0, A1, A2, A3, A4, A5};
|
|
||||||
int i, j;
|
int i, j;
|
||||||
unsigned long currTime; // non-blocking time tracker
|
unsigned long currTime; // non-blocking time tracker
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(19200);
|
Serial.begin(19200);
|
||||||
currTime = millis();
|
currTime = millis();
|
||||||
analogReadResolution(12);
|
Serial.println();
|
||||||
// adcAttachPin(A0);
|
|
||||||
// analogSetClockDiv(255);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// we might need analogSetAttenuation to make the measurement more accurate and less noisy?
|
|
||||||
if (millis() - currTime >= WAIT_TIME) { // non-blocking time delay
|
if (millis() - currTime >= WAIT_TIME) { // non-blocking time delay
|
||||||
// Serial.println();
|
|
||||||
Serial.print("[");
|
Serial.print("[");
|
||||||
for (i = 0; i < sizeof(pins)/SIZE_DIV; i++) {
|
for (i = 0; i < sizeof(pins) / SIZE_DIV; i++) {
|
||||||
|
Serial.print(analogReadMilliVolts(pins[i]), DEC);
|
||||||
// float volts = analogRead(pins[i]);
|
if (i != sizeof(pins) / SIZE_DIV - 1) { // fence-post the list print
|
||||||
// float result = volts * 3.3 / 4095;
|
|
||||||
// Serial.print(result);
|
|
||||||
|
|
||||||
float volts = analogReadMilliVolts(pins[i]);
|
|
||||||
Serial.print(volts);
|
|
||||||
// Serial.print(61319 * (3.3/volts - 1));
|
|
||||||
if (i != sizeof(pins)/SIZE_DIV - 1) {
|
|
||||||
Serial.print(", ");
|
Serial.print(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Serial.println("]");
|
Serial.println("]");
|
||||||
// Serial.println(analogReadMilliVolts(SENSOR1));
|
currTime = millis();
|
||||||
currTime = millis();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue