-
Notifications
You must be signed in to change notification settings - Fork 0
/
esp32 gradestokk.cpp
51 lines (40 loc) · 1.39 KB
/
esp32 gradestokk.cpp
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
47
48
49
50
51
// Libraries
#include <Adafruit_BME280.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
// Config
#define SCREEN_WIDTH 128 // OLED width, in pixels
#define SCREEN_HEIGHT 64 // OLED height, in pixels
// OLED display objekt I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// BME Objekt I2C
Adafruit_BME280 bme;
void configure_bme(){// Konfigurerer BME280
Serial.println("Sjekker koblingen til BME280:");
if(!bme.begin(0x76)){
Serial.println("ERROR: BME280 er ikke koblet riktig!");
while(1); // Fanger script i evig løkke
} Serial.println("BME280 er koblet riktig!");
}
////////////
void setup(){
Serial.begin(9600);
configure_bme();
// initialisering av OLED display med I2C addresse 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
delay(2000); // wait two seconds for initializing
}
void loop(){
float temperature = bme.readTemperature();
oled.clearDisplay(); // clear display
oled.setTextSize(2); // set text size
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 10); // set position to display
oled.println("Temperatur"); // set text
oled.print(temperature); oled.println(" C");
oled.display(); // display on OLED
}