arduino-sketch.ino 888 B

1234567891011121314151617181920212223242526
  1. #include "version.h"
  2. // https://www.arduino.cc/reference/en/language/functions/time/micros/
  3. const unsigned long SAMPLE_INTERVAL_MICROSECONDS = 2500L;
  4. void setup() {
  5. // $ stty -F /dev/ttyUSB0 | grep speed
  6. Serial.begin(115200);
  7. // Serial.println(PROJECT_REPO_URL);
  8. // Serial.println(PROJECT_VERSION);
  9. }
  10. unsigned long last_sample_micros = 0;
  11. void loop() {
  12. while (micros() - last_sample_micros < SAMPLE_INTERVAL_MICROSECONDS)
  13. ;
  14. last_sample_micros = micros();
  15. // > On ATmega based boards [...], it takes about 100 microseconds
  16. // > (0.0001 s) > to read an analog input, [...]
  17. // https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/
  18. unsigned short reading = analogRead(A0);
  19. // $ tail --follow /dev/ttyUSB0 | od --format=u2 --endian=big --width=2
  20. Serial.write(reading >> 8);
  21. Serial.write(reading & 0xff);
  22. }