-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4runnerproject.ino
126 lines (104 loc) · 2.68 KB
/
4runnerproject.ino
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
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_BMP085.h>
#include <ezButton.h>
#define seaLevelPressure_hPa 1013.25
Adafruit_BMP085 bmp;
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
OneWire oneWire(2);
DallasTemperature sensors(&oneWire);
ezButton button(7);
int currentTemp(0);
String strTemp(0);
void setup(void)
{
sensors.begin();
Serial.begin(9600);
button.setDebounceTime(30);
Wire.begin(); // Initialize I2C communication
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
if (!bmp.begin(0x77)) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
}
display.clearDisplay();
display.setTextSize(4);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.print("JULIE");
display.display();
delay(2000);
}
int alti(0);
String strAlti;
String strPressure;
int screen = 0.0;
int pressure = 0;
int switchCheck;
double volts;
void loop(){
button.loop();
if(button.isPressed()){
if(screen < 3) {
screen++;
}else {
screen = 0;
}
Serial.print("The button is pressed");
}
if(button.isReleased()){
Serial.print("The button has been released");
}
switch(screen) {
case 0:
sensors.requestTemperatures();
currentTemp = ((sensors.getTempCByIndex(0) * 9.0) / 5.0 + 32.0) + 0.5;
strTemp = String(currentTemp);
strTemp = String(currentTemp) + " " + "F";
display.clearDisplay();
display.setTextSize(3);
display.setCursor(0, 0);
display.print(strTemp);
display.setCursor(0,25);
display.setTextSize(1);
display.print("Temperature");
display.display();
break;
case 1:
alti = bmp.readAltitude(seaLevelPressure_hPa * 100) * 3.28;
strAlti = String(alti) + " Ft";
display.clearDisplay();
display.setTextSize(3);
display.setCursor(0, 0);
display.print(strAlti);
display.setCursor(0,25);
display.setTextSize(1);
display.print("Altitude");
display.display();
break;
case 2:
pressure = bmp.readPressure() / 100;
strPressure = String(pressure) + " kPa";
display.clearDisplay();
display.setTextSize(3);
display.setCursor(0, 0);
display.print(strPressure);
display.setCursor(0,25);
display.setTextSize(1);
display.print("Pressure");
display.display();
break;
}
//delay(100);
}