arduino-sketch.ino 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <Adafruit_SH110X.h>
  2. #include "version.h"
  3. const long REFERENCE_VOLTAGE_mV = 5000;
  4. const long ANALOG_READ_MAX = 2 << 10 - 1;
  5. const uint8_t DISPLAY_WIDTH = 128;
  6. const uint8_t DISPLAY_HEIGHT = 64;
  7. // https://startingelectronics.org/tutorials/arduino/modules/OLED-128x64-I2C-display/
  8. const uint8_t DISPLAY_I2C_ADDRESS = 0x3C;
  9. Adafruit_SH1106G display(DISPLAY_WIDTH, DISPLAY_HEIGHT);
  10. void setup() {
  11. // $ stty -F /dev/ttyUSB0 | grep speed
  12. Serial.begin(115200);
  13. Serial.println(PROJECT_REPO_URL);
  14. Serial.println(PROJECT_VERSION);
  15. if (!display.begin(DISPLAY_I2C_ADDRESS, true)) {
  16. Serial.println("failed to init display");
  17. while (true)
  18. ;
  19. }
  20. display.clearDisplay();
  21. display.setTextColor(SH110X_WHITE);
  22. display.println(PROJECT_REPO_URL);
  23. display.println(PROJECT_VERSION);
  24. display.display();
  25. delay(2000);
  26. display.setTextSize(4);
  27. }
  28. void loop() {
  29. display.clearDisplay();
  30. display.setCursor(0, 0);
  31. display.println(
  32. (long)analogRead(A0) * REFERENCE_VOLTAGE_mV / ANALOG_READ_MAX
  33. );
  34. display.print("mV");
  35. display.display();
  36. delay(100); // ms
  37. }