123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #include <Adafruit_SSD1306.h>
- #include "version.h"
- 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;
- const double known_resistor_ohm = 10e3;
- Adafruit_SSD1306 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(SSD1306_SWITCHCAPVCC, DISPLAY_I2C_ADDRESS)) {
- Serial.println("failed to init display");
- while (true)
- ;
- }
- display.clearDisplay();
- display.setTextColor(SSD1306_WHITE);
- display.println(PROJECT_REPO_URL);
- display.println(PROJECT_VERSION);
- display.display();
- delay(2000);
- display.setTextSize(3);
- }
- void loop() {
- display.clearDisplay();
- display.setCursor(0, 0);
- // https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/
- int voltage = analogRead(A0);
- if (voltage == 0) {
- display.println("inf");
- } else {
- double unknown_resistor_ohm =
- known_resistor_ohm * ((double)1024 / voltage - 1);
- display.println(unknown_resistor_ohm / 1000);
- }
- display.print("kOhm");
- display.display();
- delay(100); // ms
- }
|