#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define SCREEN_WIDTH 128 // OLED width, in pixels
#define SCREEN_HEIGHT 64 // OLED height, in pixels
Adafruit_SSD1306 OLED(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
OneWire Bell(10);
DallasTemperature senser (&Bell);
void setup() {
OLED.begin(SSD1306_SWITCHCAPVCC, 0x3C);
delay(2000); // wait two seconds for initializing
Serial.begin(9600);
}
void loop() {
senser.requestTemperatures();
float temp=senser.getTempCByIndex(0);
Serial.println("Temperature is:"+ String(temp,1)+"°C");
OLED.clearDisplay();
OLED.setTextColor(WHITE, BLACK); //Text is white ,background is black
OLED.setCursor(0, 0);
OLED.setTextSize(2);
OLED.print("Pitchaya Khumkinam");
OLED.setCursor(90, 50);
OLED.println("C");
OLED.setTextSize(1);
OLED.setTextColor(BLACK, WHITE); // 'inverted' text
OLED.setTextColor(WHITE, BLACK); // 'inverted' text again
OLED.setCursor(35, 50);
OLED.setTextSize(2);
OLED.print(temp, 1);
OLED.drawCircle(88, 50, 2, WHITE); // print degree symbols ( ° )
OLED.display();
delay(250);
}