50
edits
Changes
Jump to navigation
Jump to search
→Code Samples
// --- setup() and loop()
void setup() {
doLowLevelConfig();
pinMode(2, INPUT_PULLUP); // Changing this pin requires changes in doLowLevelConfig()
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
// Initialize communication with PC.
Serial.begin(115200);
Serial.println(getHeader());
}
void loop() {
if (readComplete) {
readComplete = false;
// TODO - format output using C-style strings instead
sample = sampleTime;
for (uint8_t i = 0; i <= maxIndex; i++) {
sample += "," + String(rawADC[i]);
}
Serial.println(sample); // Blocking? Technically, but this is usually fast.
}
// Handle button presses (or releases in our case).
if (btnReleased) {
btnReleased = false;
if (recording) {
// If we're recording, stop.
bitClear(ADCSRA, ADEN);
recording = false;
}
else {
// If we're not recording, start.
recording = true;
bitSet(ADCSRA, ADEN);
}
}
}
</pre>