const uint32_t RATE_HZ = 10000;
const size_t BLOCK = 1000;
uint16_t buffers[2][BLOCK];
int filling = 0;
unsigned long last_blink = 0;
void processBlock(const uint16_t* block) {
float sum = 0;
for (size_t i = 0; i < BLOCK; i++) sum += block[i];
const float mean = sum / BLOCK;
float squares = 0;
for (size_t i = 0; i < BLOCK; i++) squares += (block[i] - mean) * (block[i] - mean);
Serial.print(mean * mv_per_step, 1);
Serial.print(sqrtf(squares / BLOCK) * mv_per_step, 2);
}
}
const int full = filling;
filling = 1 - filling;
processBlock(buffers[full]);
}
if (
millis() - last_blink >= 250) {
}
}
@ OUTPUT
Definition Common.h:40
SerialUSBClass Serial
USB serial port, the one the Serial Monitor uses.
void analogReadResolution(int bits)
Sets the number of bits analogRead() returns, for every analog pin.
bool analogBurstDone()
Whether the burst started by analogStartBurst() has finished.
uint32_t analogStartBurst(pin_size_t pin, uint16_t *buffer, size_t count, uint32_t sample_rate_hz)
Starts a burst like analogReadBurst(), but returns at once; the samples are taken in the background.
uint32_t analogFullScaleMillivolts(pin_size_t pin)
Voltage that reads as full scale on an analog pin.
void digitalWrite(pin_size_t pinNumber, PinStatus status)
Sets an output pin HIGH (3.3 V) or LOW (0 V).
PinStatus digitalRead(pin_size_t pinNumber)
Reads the level on a pin.
void pinMode(pin_size_t pinNumber, PinMode pinMode)
Sets a pin as an input or an output.
void loop(void)
Written by the sketch: runs over and over after setup(), on core 0.
void setup(void)
Written by the sketch: runs once after reset, on core 0.
unsigned long millis(void)
Milliseconds since the board started.
uint8_t pin_size_t
Type for Arduino pin numbers (uint8_t).
Definition Common.h:112
#define LED_BUILTIN
On-board LED.
Definition pins_arduino.h:63