arduino-sketch.ino 928 B

123456789101112131415161718192021222324252627
  1. #include "version.h"
  2. // https://www.arduino.cc/reference/en/language/functions/time/micros/
  3. const unsigned long SAMPLE_INTERVAL_MICROSECONDS = 1000000L;
  4. void setup() {
  5. // $ stty -F /dev/ttyUSB0 | grep speed
  6. Serial.begin(115200);
  7. // Serial.println("https://git.hammerle.me/fphammerle/TODO");
  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. delay(1);
  14. }
  15. // > On ATmega based boards [...], it takes about 100 microseconds (0.0001
  16. // 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. last_sample_micros = micros();
  23. }