1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#include <Wire.h> #include "SSD1306.h" SSD1306 display(0x3c, 4, 5); int outTemp = 0; int outHum = 0; int firstRun = 1; String lastValidTemp = ""; String lastValidHum = ""; void setup() { display.init(); display.flipScreenVertically(); } void loop() { display.clear(); drawLM35(); // Read and show LM35 sensor on OLED display.display(); // Display all in OLED firstRun = 0; } void drawLM35() { int x = 0; int y = 0; int val = 0; for (int i = 0; i < 10; i++) { val += analogRead(A0); delay(200); } int templm35 = val * 33 / 1023; display.setFont(ArialMT_Plain_16); display.setTextAlignment(TEXT_ALIGN_LEFT); display.drawString(30 + x, y, "freeelec.ir"); String temprature(templm35); display.setFont(ArialMT_Plain_10); display.setTextAlignment(TEXT_ALIGN_LEFT); display.drawString(20 + x, 25 + y, "LM35 Temperature"); display.setFont(ArialMT_Plain_16); display.drawString(46, 48, temprature + "^C"); } |