//INCLUDES
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_GFX.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <SPI.h>
//DEFINES
#define SENSOR 16
#define SCREEN_HEIGHT 128
#define SCREEN_WIDTH 64
OneWire oneWire(SENSOR);
DallasTemperature DS18B20(&oneWire);
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
byte FPS = 8; // FPS Mode, options: 1 = 23, 2 = 24, 3 = 25, 4 = 29, 5 = 30, 6 = 50, 7 = 59, 8 = 60
byte SPEED = 1; // Pulse speed, 1 = 1 pulse per frame, 2 = 1 pulse per 10 frames, 3 = 1 pulse per second, 4 = 1 pulse per minute
//VARIABLES
float tempC;
float tempF;
float tempK;
/////////////////////VOIDS/////////////////////////
void disptemp(void) {
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0,0);
display.setTextColor(WHITE);
display.println (F("T:"));
display.println (tempC);
display.display ();
delay(500);
}
void upptemp(void) {
display.clearDisplay();
display.setCursor(0,0);
display.println (F("T:"));
display.println (tempC);
display.display ();
delay(500);
}
void obtemp (void) {
DS18B20.requestTemperatures(); //request for values
tempC = DS18B20.getTempCByIndex(0); // read temperature in °C
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, termometer!");
//Pin Declarations
pinMode(22,OUTPUT);
pinMode(16, INPUT);
//SENSOR STARTUP
DS18B20.begin();
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
// Draw a single pixel in white
display.drawPixel(10, 10, WHITE);
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
delay(500);
disptemp();
}
void loop() {
// put your main code here, to run repeatedly:
//MAIN CPP
obtemp();
//Disp
upptemp();
}