12345678910111213141516171819202122 |
- // https://www.arduino.cc/reference/en/language/functions/time/micros/
- const unsigned long SAMPLE_INTERVAL_MICROSECONDS = 2500L;
- void setup() {
- // $ stty -F /dev/ttyUSB0 | grep speed
- Serial.begin(115200);
- }
- unsigned long last_sample_micros = 0;
- void loop() {
- while (micros() - last_sample_micros < SAMPLE_INTERVAL_MICROSECONDS)
- ;
- last_sample_micros = micros();
- // > On ATmega based boards [...], it takes about 100 microseconds
- // > (0.0001 s) > to read an analog input, [...]
- // https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/
- unsigned short reading = analogRead(A0);
- // $ tail --follow /dev/ttyUSB0 | od --format=u2 --endian=big --width=2
- Serial.write(reading >> 8);
- Serial.write(reading & 0xff);
- }
|