[175] | 1 | /*
|
---|
| 2 | Weather Station
|
---|
| 3 |
|
---|
| 4 | A simple Arduino sketch that reads values from temperature, humidity and pressure sensors
|
---|
| 5 | of the Lucky Shield and display it in the OLED add-on (and also via Serial).
|
---|
| 6 |
|
---|
| 7 | created Mar 2016
|
---|
| 8 | by andrea@arduino.org,
|
---|
| 9 | sergio@arduino.org
|
---|
| 10 | */
|
---|
| 11 |
|
---|
| 12 | #include <Lucky.h>
|
---|
| 13 | #include <Wire.h>
|
---|
| 14 |
|
---|
| 15 | String tmp_lbl, tmp_um, tmp_val, hum_lbl, hum_um, hum_val, pre_lbl, pre_um, pre_val;
|
---|
| 16 | void setup() {
|
---|
| 17 | Serial.begin(9600);
|
---|
| 18 |
|
---|
| 19 | lucky.begin();
|
---|
| 20 |
|
---|
| 21 | //setup the Lucky OLED
|
---|
| 22 | lucky.oled().setTextSize(0.5);
|
---|
| 23 | lucky.oled().setTextColor(WHITE);
|
---|
| 24 | lucky.oled().clearDisplay();
|
---|
| 25 |
|
---|
| 26 | tmp_lbl = "Temper.: ";
|
---|
| 27 | hum_lbl = "Humidity:";
|
---|
| 28 | pre_lbl = "Pressure:";
|
---|
| 29 |
|
---|
| 30 | tmp_um = " C.";
|
---|
| 31 | hum_um = " %";
|
---|
| 32 | pre_um = " hPa";
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | void loop() {
|
---|
| 36 |
|
---|
| 37 | lucky.oled().clearDisplay();
|
---|
| 38 |
|
---|
| 39 | tmp_val = String(lucky.environment().temperature());
|
---|
| 40 | lucky.oled().setCursor(5, 10);
|
---|
| 41 | lucky.oled().print(tmp_lbl + tmp_val + tmp_um);
|
---|
| 42 | Serial.println(tmp_lbl + tmp_val + tmp_um);
|
---|
| 43 |
|
---|
| 44 | hum_val = String(lucky.environment().humidity());
|
---|
| 45 | lucky.oled().setCursor(5, 30);
|
---|
| 46 | lucky.oled().print(hum_lbl + hum_val + hum_um);
|
---|
| 47 | Serial.println(hum_lbl + hum_val + hum_um);
|
---|
| 48 |
|
---|
| 49 | pre_val = String(lucky.environment().pressure() / 100.0F);
|
---|
| 50 | lucky.oled().setCursor(5, 50);
|
---|
| 51 | lucky.oled().print(pre_lbl + pre_val + pre_um);
|
---|
| 52 | Serial.println(pre_lbl + pre_val + pre_um);
|
---|
| 53 |
|
---|
| 54 | lucky.oled().display();
|
---|
| 55 |
|
---|
| 56 | delay(1000);
|
---|
| 57 | }
|
---|