Created
February 16, 2022 16:41
-
-
Save blubbel01/128d06e0c1915647cc18ecdc5210bb40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <Wire.h> | |
#include <OneWire.h> | |
#include <DallasTemperature.h> | |
#include <Adafruit_GFX.h> | |
#include <Adafruit_SSD1306.h> | |
#define ONE_WIRE_BUS_TEMPERATURE 4 | |
OneWire oneWire_temp(ONE_WIRE_BUS_TEMPERATURE); | |
DallasTemperature sensor_temp(&oneWire_temp); | |
#define SCREEN_WIDTH 128 // OLED display width, in pixels | |
#define SCREEN_HEIGHT 32 // OLED display height, in pixels | |
#define OLED_RESET 4 | |
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 | |
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); | |
void setup() { | |
Serial.begin(9600); | |
Serial.println(F("START!")); | |
// start temp reciver | |
sensor_temp.begin(); | |
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally | |
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { | |
Serial.println(F("SSD1306 allocation failed")); | |
for(;;); // Don't proceed, loop forever | |
} | |
} | |
void loop() { | |
sensor_temp.requestTemperatures(); | |
display.clearDisplay(); | |
display.setTextSize(1); | |
display.setTextColor(WHITE); | |
display.setCursor(0, 0); | |
display.print("Temp: "); | |
display.setTextSize(3); | |
display.println(sensor_temp.getTempCByIndex(0)); | |
display.display(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment