Open main menu

Changes

Events/2020/AVR

957 bytes added, 12:58, 24 January 2021
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>
50
edits