Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BMP180 N5110 mbed
Diff: main.cpp
- Revision:
- 4:0302731434a5
- Parent:
- 3:c9162dc9ba24
- Child:
- 5:3246c4b8362c
--- a/main.cpp Thu Apr 30 16:25:48 2015 +0000
+++ b/main.cpp Thu Apr 30 17:14:08 2015 +0000
@@ -8,9 +8,8 @@
// Can give better performance due to current limitation from GPIO pin
BMP180 bmp180(p28,p27); // SDA, SCL
-Serial serial(USBTX,USBRX);
-AnalogIn BUT1(p15);
+InterruptIn buttonleft(p15);
AnalogIn BUT2(p16);
AnalogIn POT(p20);
@@ -20,7 +19,10 @@
float temperature;
float pressure;
+int buttonFlag=0;
+
void clearCells();
+void menu();
Timeout callT;
Timeout callP;
@@ -38,6 +40,10 @@
timerPFlag = 1;
}
+void buttonPressed(){
+ buttonFlag=1;
+}
+
void callTemp(){
Measurement measurement;
clearCells();
@@ -64,6 +70,7 @@
void readTemp(){
callT.attach(&callTemp,0.1);
+ timerT.attach(&timerTExpired,60);
while(1){
if (timerTFlag){
timerTFlag=0;
@@ -77,11 +84,16 @@
lcd.printString(bufferT,10,2);
}
}
+ if (buttonFlag){
+ buttonFlag=0;
+ menu();
+ }
}
}
void readPress(){
callP.attach(&callPress,0.1);
+ timerP.attach(&timerPExpired,1800);
while(1){
if (timerPFlag){
timerPFlag=0;
@@ -95,6 +107,10 @@
lcd.printString(bufferP,0,2);
}
}
+ if (buttonFlag){
+ buttonFlag=0;
+ menu();
+ }
}
}
@@ -106,6 +122,7 @@
}
void tempGraph(){
+ timerT.attach(&timerTExpired,2);
int j=0; //start graph on left hand side of screen
while(1){
lcd.printString("Menu",0,5);
@@ -119,10 +136,15 @@
lcd.plotArray(tempArray); //plot the array
wait(0.1); //wait one second before plotting the next point
}
+ if (buttonFlag){
+ buttonFlag=0;
+ menu();
+ }
}
}
void pressGraph(){
+ timerP.attach(&timerPExpired,2);
int j=0;
while(1){
lcd.printString("Menu",0,5);
@@ -134,12 +156,17 @@
pressArray[j]=(pressure/1100);
j++;
lcd.plotArray(pressArray);
+ wait(0.1);
+ }
+ if (buttonFlag){
+ buttonFlag=0;
+ menu();
}
}
}
-void menu()
-{
+void menu(){
+ buttonleft.rise(&buttonPressed);
while(1) {
wait (0.1);
lcd.normalMode(); //normal LCD colour mode
@@ -150,7 +177,8 @@
lcd.printString(">",80,2);
lcd.printString("Graph",0,5);
lcd.printString("Current",43,5);
- if (BUT1>0.9) { //left button takes the user to the graph option
+ if (buttonFlag){ //left button takes the user to the graph option
+ buttonFlag=0;
clearCells();
tempGraph();
}
@@ -166,7 +194,8 @@
lcd.printString(">",80,2);
lcd.printString("Graph",0,5);
lcd.printString("Current",43,5);
- if (BUT1>0.9) {
+ if (buttonFlag) {
+ buttonFlag=0;
clearCells();
pressGraph();
}
@@ -181,7 +210,8 @@
lcd.printString("<",0,2);
lcd.printString("Graph",0,5);
lcd.printString("Current",43,5);
- if (BUT1>0.9) {
+ if (buttonFlag) {
+ buttonFlag=0;
clearCells();
//lightGraph();
}
@@ -207,7 +237,5 @@
int main(){
lcd.init();
bmp180.init();
- timerT.attach(&timerTExpired,60);
- timerP.attach(&timerPExpired,1800);
menu();
}
\ No newline at end of file