|
@@ -7,6 +7,8 @@ const uint8_t DISPLAY_HEIGHT = 64;
|
|
// https://startingelectronics.org/tutorials/arduino/modules/OLED-128x64-I2C-display/
|
|
// https://startingelectronics.org/tutorials/arduino/modules/OLED-128x64-I2C-display/
|
|
const uint8_t DISPLAY_I2C_ADDRESS = 0x3C;
|
|
const uint8_t DISPLAY_I2C_ADDRESS = 0x3C;
|
|
|
|
|
|
|
|
+const double known_resistor_ohm = 10e3;
|
|
|
|
+
|
|
Adafruit_SSD1306 display(DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
|
Adafruit_SSD1306 display(DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
|
|
|
|
|
void setup() {
|
|
void setup() {
|
|
@@ -25,13 +27,22 @@ void setup() {
|
|
display.println(PROJECT_VERSION);
|
|
display.println(PROJECT_VERSION);
|
|
display.display();
|
|
display.display();
|
|
delay(2000);
|
|
delay(2000);
|
|
- display.setTextSize(5);
|
|
|
|
|
|
+ display.setTextSize(3);
|
|
}
|
|
}
|
|
|
|
|
|
void loop() {
|
|
void loop() {
|
|
display.clearDisplay();
|
|
display.clearDisplay();
|
|
display.setCursor(0, 0);
|
|
display.setCursor(0, 0);
|
|
- display.print(analogRead(A0));
|
|
|
|
|
|
+ // 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();
|
|
display.display();
|
|
delay(100); // ms
|
|
delay(100); // ms
|
|
}
|
|
}
|