// report.ino -- A demo of millis-based periodic status reporting
// https://wokwi.com/projects/408753591671265281
//
// Every 1000ms, this program reads and reports the analog and digital staus of each pin.
//
// configure pullup resistors? zero means floating, non-zero means pullup
const int pullup[] = {0, 0, // RX,TX on Uno
0, 0, 0, // 2,3,4
0, 0, 0, 0, 0, // 5-9
0, 0, 0, 0, // 10,11,12,13
0, 0, 0, 0, 0, 0 // A0, A1 A2 A3 A4 A5
};
void setup() {
Serial.begin(115200);
// do INPUT_PULLUP on everything?
for (int ii = 2; ii < NUM_DIGITAL_PINS; ++ii) {
if (pullup[ii] != 0 ) pinMode(ii, INPUT_PULLUP);
}
}
void loop() {
report();
}
void report() {
auto now = millis(); // https://www.arduino.cc/reference/en/language/functions/time/millis/
const typeof(now) interval = 1000;
static typeof(now) last = -interval; // schedule to trigger immediately
if (now - last >= interval) { // Expired?
last += interval; // Advance phase-locked with the processor clock
//while(now - last >= interval){last += interval;} // Advance multiple times. Needed only if loop() is stupidly slow
Serial.print(now);
Serial.print("ms");
for ( int ii = 0; ii < NUM_ANALOG_INPUTS; ++ii) {
Serial.print(" ");
Serial.print(analogRead(ii));
}
for ( int ii = 0; ii < NUM_DIGITAL_PINS; ++ii) {
Serial.print(" ");
Serial.print(digitalRead(ii));
}
Serial.println();
}
}