-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0.0.2.ino
More file actions
129 lines (99 loc) · 2.86 KB
/
Copy path0.0.2.ino
File metadata and controls
129 lines (99 loc) · 2.86 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//////////////////////////////////
/// Noah Polzer ///
/// pono1012@hs-karlsruhe.de ///
/// kleine Wetterstation ///
/// 26.06.2020 ///
/// ///
/// ///
//////////////////////////////////
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET 4
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
static const unsigned char PROGMEM logo_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
float temperature, humidity, pressure, altitude, lux;
int lightPin = 32;
int light = 0;
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.display();
delay(2000);
display.clearDisplay();
bme.begin(0x76);
}
void loop() {
temperature = bme.readTemperature();
humidity = bme.readHumidity();
pressure = bme.readPressure() / 100.0F;
altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
light = analogRead(lightPin);
lightolux();
output();
}
void output() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(10, 0);
display.println(F("Mini-Wetterstation"));
display.setCursor(10, 16);
display.print("Temp:");
display.setCursor(70, 16);
display.println(temperature);
display.setCursor(10, 26);
display.println("Lftfchtg:");
display.setCursor(70, 26);
display.println(humidity);
display.setCursor(10, 36);
display.println("Lux:");
display.setCursor(70, 36);
display.println(lux);
display.setCursor(10, 46);
display.println("Hoehe:");
display.setCursor(70, 46);
display.println(altitude);
display.display();
delay(2000);
}
void lightolux() //Näherungsweise
{
float xplus=47.6190476;
float voltage = light * (3.3 / 1023.0);
float ma = ( voltage / 250 ) * 100000;
lux = (0.21) * (ma-xplus) + 10;
if(ma <= 10)
{
lux = 1/10 * ma;
}
}