12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #include <Adafruit_SH110X.h>
- #include "version.h"
- const long REFERENCE_VOLTAGE_mV = 5000;
- const long ANALOG_READ_MAX = 2 << 10 - 1;
- const uint8_t DISPLAY_WIDTH = 128;
- const uint8_t DISPLAY_HEIGHT = 64;
- // https://startingelectronics.org/tutorials/arduino/modules/OLED-128x64-I2C-display/
- const uint8_t DISPLAY_I2C_ADDRESS = 0x3C;
- Adafruit_SH1106G display(DISPLAY_WIDTH, DISPLAY_HEIGHT);
- void setup() {
- // $ stty -F /dev/ttyUSB0 | grep speed
- Serial.begin(115200);
- Serial.println(PROJECT_REPO_URL);
- Serial.println(PROJECT_VERSION);
- if (!display.begin(DISPLAY_I2C_ADDRESS, true)) {
- Serial.println("failed to init display");
- while (true)
- ;
- }
- display.clearDisplay();
- display.setTextColor(SH110X_WHITE);
- display.println(PROJECT_REPO_URL);
- display.println(PROJECT_VERSION);
- display.display();
- delay(2000);
- display.setTextSize(4);
- }
- void loop() {
- display.clearDisplay();
- display.setCursor(0, 0);
- display.println(
- (long)analogRead(A0) * REFERENCE_VOLTAGE_mV / ANALOG_READ_MAX
- );
- display.print("mV");
- display.display();
- delay(100); // ms
- }
|