Orla Gilson / Mbed 2 deprecated WeatherLogger

Dependencies:   BMP180 N5110 mbed

Committer:
orlagilson
Date:
Thu May 07 16:11:21 2015 +0000
Revision:
5:3246c4b8362c
Parent:
4:0302731434a5
Child:
6:1b5603fd1a9c
Sixth commit, doxygen commenting begun, all functions done.; Variables need to be completed.; Light measurements need to be added.; Error function partially added, LED works as designed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
orlagilson 0:2fd314d76f37 1 #include "mbed.h"
orlagilson 0:2fd314d76f37 2 #include "BMP180.h"
orlagilson 0:2fd314d76f37 3 #include "N5110.h"
orlagilson 0:2fd314d76f37 4
orlagilson 0:2fd314d76f37 5 // VCC,SCE,RST,D/C,MOSI,SCLK,LED
orlagilson 0:2fd314d76f37 6 N5110 lcd(p7,p8,p9,p10,p11,p13,p26);
orlagilson 0:2fd314d76f37 7 // Can also power (VCC) directly from VOUT (3.3 V) -
orlagilson 0:2fd314d76f37 8 // Can give better performance due to current limitation from GPIO pin
orlagilson 0:2fd314d76f37 9
orlagilson 0:2fd314d76f37 10 BMP180 bmp180(p28,p27); // SDA, SCL
orlagilson 0:2fd314d76f37 11
orlagilson 4:0302731434a5 12 InterruptIn buttonleft(p15);
orlagilson 0:2fd314d76f37 13 AnalogIn BUT2(p16);
orlagilson 0:2fd314d76f37 14 AnalogIn POT(p20);
orlagilson 5:3246c4b8362c 15 DigitalOut led(p25);
orlagilson 0:2fd314d76f37 16
orlagilson 0:2fd314d76f37 17 int nx=84;
orlagilson 0:2fd314d76f37 18 int ny=48;
orlagilson 0:2fd314d76f37 19 int i,j;
orlagilson 2:6b564e388747 20 float temperature;
orlagilson 2:6b564e388747 21 float pressure;
orlagilson 0:2fd314d76f37 22
orlagilson 4:0302731434a5 23 int buttonFlag=0;
orlagilson 4:0302731434a5 24
orlagilson 0:2fd314d76f37 25 void clearCells();
orlagilson 4:0302731434a5 26 void menu();
orlagilson 0:2fd314d76f37 27
orlagilson 3:c9162dc9ba24 28 Timeout callT;
orlagilson 3:c9162dc9ba24 29 Timeout callP;
orlagilson 3:c9162dc9ba24 30
orlagilson 1:1accd82f4281 31 Ticker timerT;
orlagilson 1:1accd82f4281 32 Ticker timerP;
orlagilson 5:3246c4b8362c 33 Ticker timerE;
orlagilson 1:1accd82f4281 34
orlagilson 1:1accd82f4281 35 int timerTFlag = 0;
orlagilson 1:1accd82f4281 36 int timerPFlag = 0;
orlagilson 5:3246c4b8362c 37 int timerEFlag = 0;
orlagilson 1:1accd82f4281 38
orlagilson 1:1accd82f4281 39 void timerTExpired(){
orlagilson 1:1accd82f4281 40 timerTFlag = 1;
orlagilson 1:1accd82f4281 41 }
orlagilson 1:1accd82f4281 42 void timerPExpired(){
orlagilson 1:1accd82f4281 43 timerPFlag = 1;
orlagilson 1:1accd82f4281 44 }
orlagilson 5:3246c4b8362c 45 void timerEExpired(){
orlagilson 5:3246c4b8362c 46 timerEFlag = 1;
orlagilson 5:3246c4b8362c 47 }
orlagilson 1:1accd82f4281 48
orlagilson 4:0302731434a5 49 void buttonPressed(){
orlagilson 4:0302731434a5 50 buttonFlag=1;
orlagilson 4:0302731434a5 51 }
orlagilson 4:0302731434a5 52
orlagilson 5:3246c4b8362c 53 void error(){
orlagilson 5:3246c4b8362c 54 timerE.attach(&timerEExpired,2.0);
orlagilson 5:3246c4b8362c 55 while(1){
orlagilson 5:3246c4b8362c 56 if (timerEFlag){
orlagilson 5:3246c4b8362c 57 timerEFlag=0;
orlagilson 5:3246c4b8362c 58 led=1;
orlagilson 5:3246c4b8362c 59 wait(1.0);
orlagilson 5:3246c4b8362c 60 led=0;
orlagilson 5:3246c4b8362c 61 }
orlagilson 5:3246c4b8362c 62 }
orlagilson 5:3246c4b8362c 63 }
orlagilson 5:3246c4b8362c 64
orlagilson 5:3246c4b8362c 65
orlagilson 3:c9162dc9ba24 66 void callTemp(){
orlagilson 3:c9162dc9ba24 67 Measurement measurement;
orlagilson 3:c9162dc9ba24 68 clearCells();
orlagilson 3:c9162dc9ba24 69 lcd.printString("Menu",0,5);
orlagilson 3:c9162dc9ba24 70 char bufferT[14];
orlagilson 3:c9162dc9ba24 71 measurement = bmp180.readValues();
orlagilson 3:c9162dc9ba24 72 int length=sprintf(bufferT,"T = %.2f C",measurement.temperature);
orlagilson 3:c9162dc9ba24 73 if (length<=14){
orlagilson 3:c9162dc9ba24 74 lcd.printString(bufferT,10,2);
orlagilson 3:c9162dc9ba24 75 }
orlagilson 3:c9162dc9ba24 76 }
orlagilson 3:c9162dc9ba24 77
orlagilson 3:c9162dc9ba24 78 void callPress(){
orlagilson 3:c9162dc9ba24 79 Measurement measurement;
orlagilson 3:c9162dc9ba24 80 clearCells();
orlagilson 3:c9162dc9ba24 81 lcd.printString("Menu",0,5);
orlagilson 3:c9162dc9ba24 82 char bufferP[14];
orlagilson 3:c9162dc9ba24 83 measurement = bmp180.readValues();
orlagilson 3:c9162dc9ba24 84 int length=sprintf(bufferP,"P = %.2f mb",measurement.pressure);
orlagilson 3:c9162dc9ba24 85 if (length<=14){
orlagilson 3:c9162dc9ba24 86 lcd.printString(bufferP,0,2);
orlagilson 3:c9162dc9ba24 87 }
orlagilson 3:c9162dc9ba24 88 }
orlagilson 3:c9162dc9ba24 89
orlagilson 0:2fd314d76f37 90 void readTemp(){
orlagilson 3:c9162dc9ba24 91 callT.attach(&callTemp,0.1);
orlagilson 4:0302731434a5 92 timerT.attach(&timerTExpired,60);
orlagilson 0:2fd314d76f37 93 while(1){
orlagilson 1:1accd82f4281 94 if (timerTFlag){
orlagilson 1:1accd82f4281 95 timerTFlag=0;
orlagilson 2:6b564e388747 96 Measurement measurement;
orlagilson 1:1accd82f4281 97 clearCells();
orlagilson 3:c9162dc9ba24 98 lcd.printString("Menu",0,5);
orlagilson 1:1accd82f4281 99 char bufferT[14];
orlagilson 1:1accd82f4281 100 measurement = bmp180.readValues();
orlagilson 1:1accd82f4281 101 int length=sprintf(bufferT,"T = %.2f C",measurement.temperature);
orlagilson 1:1accd82f4281 102 if (length<=14){
orlagilson 1:1accd82f4281 103 lcd.printString(bufferT,10,2);
orlagilson 1:1accd82f4281 104 }
orlagilson 0:2fd314d76f37 105 }
orlagilson 4:0302731434a5 106 if (buttonFlag){
orlagilson 4:0302731434a5 107 buttonFlag=0;
orlagilson 4:0302731434a5 108 menu();
orlagilson 4:0302731434a5 109 }
orlagilson 0:2fd314d76f37 110 }
orlagilson 0:2fd314d76f37 111 }
orlagilson 0:2fd314d76f37 112
orlagilson 0:2fd314d76f37 113 void readPress(){
orlagilson 3:c9162dc9ba24 114 callP.attach(&callPress,0.1);
orlagilson 4:0302731434a5 115 timerP.attach(&timerPExpired,1800);
orlagilson 0:2fd314d76f37 116 while(1){
orlagilson 1:1accd82f4281 117 if (timerPFlag){
orlagilson 1:1accd82f4281 118 timerPFlag=0;
orlagilson 2:6b564e388747 119 Measurement measurement;
orlagilson 1:1accd82f4281 120 clearCells();
orlagilson 3:c9162dc9ba24 121 lcd.printString("Menu",0,5);
orlagilson 1:1accd82f4281 122 char bufferP[14];
orlagilson 1:1accd82f4281 123 measurement = bmp180.readValues();
orlagilson 1:1accd82f4281 124 int length=sprintf(bufferP,"P = %.2f mb",measurement.pressure);
orlagilson 1:1accd82f4281 125 if (length<=14){
orlagilson 1:1accd82f4281 126 lcd.printString(bufferP,0,2);
orlagilson 1:1accd82f4281 127 }
orlagilson 0:2fd314d76f37 128 }
orlagilson 4:0302731434a5 129 if (buttonFlag){
orlagilson 4:0302731434a5 130 buttonFlag=0;
orlagilson 4:0302731434a5 131 menu();
orlagilson 4:0302731434a5 132 }
orlagilson 0:2fd314d76f37 133 }
orlagilson 0:2fd314d76f37 134 }
orlagilson 0:2fd314d76f37 135
orlagilson 2:6b564e388747 136 void measurement(){
orlagilson 2:6b564e388747 137 Measurement measurement;
orlagilson 2:6b564e388747 138 measurement=bmp180.readValues();
orlagilson 2:6b564e388747 139 temperature=measurement.temperature;
orlagilson 2:6b564e388747 140 pressure=measurement.pressure;
orlagilson 2:6b564e388747 141 }
orlagilson 2:6b564e388747 142
orlagilson 2:6b564e388747 143 void tempGraph(){
orlagilson 4:0302731434a5 144 timerT.attach(&timerTExpired,2);
orlagilson 2:6b564e388747 145 int j=0; //start graph on left hand side of screen
orlagilson 2:6b564e388747 146 while(1){
orlagilson 3:c9162dc9ba24 147 lcd.printString("Menu",0,5);
orlagilson 2:6b564e388747 148 if (timerTFlag){
orlagilson 2:6b564e388747 149 timerTFlag=0;
orlagilson 2:6b564e388747 150 clearCells();
orlagilson 2:6b564e388747 151 float tempArray[84]; //create array of temperature values
orlagilson 2:6b564e388747 152 measurement(); //read in the measured values of temperature
orlagilson 2:6b564e388747 153 tempArray[j]=(temperature/47);
orlagilson 2:6b564e388747 154 j++; //add one to j so that the next point plotted moves across the screen by one pixel
orlagilson 2:6b564e388747 155 lcd.plotArray(tempArray); //plot the array
orlagilson 2:6b564e388747 156 wait(0.1); //wait one second before plotting the next point
orlagilson 2:6b564e388747 157 }
orlagilson 4:0302731434a5 158 if (buttonFlag){
orlagilson 4:0302731434a5 159 buttonFlag=0;
orlagilson 4:0302731434a5 160 menu();
orlagilson 4:0302731434a5 161 }
orlagilson 2:6b564e388747 162 }
orlagilson 2:6b564e388747 163 }
orlagilson 2:6b564e388747 164
orlagilson 2:6b564e388747 165 void pressGraph(){
orlagilson 4:0302731434a5 166 timerP.attach(&timerPExpired,2);
orlagilson 2:6b564e388747 167 int j=0;
orlagilson 2:6b564e388747 168 while(1){
orlagilson 3:c9162dc9ba24 169 lcd.printString("Menu",0,5);
orlagilson 2:6b564e388747 170 if (timerPFlag){
orlagilson 2:6b564e388747 171 timerPFlag=0;
orlagilson 2:6b564e388747 172 clearCells();
orlagilson 2:6b564e388747 173 float pressArray[84];
orlagilson 2:6b564e388747 174 measurement();
orlagilson 2:6b564e388747 175 pressArray[j]=(pressure/1100);
orlagilson 2:6b564e388747 176 j++;
orlagilson 2:6b564e388747 177 lcd.plotArray(pressArray);
orlagilson 4:0302731434a5 178 wait(0.1);
orlagilson 4:0302731434a5 179 }
orlagilson 4:0302731434a5 180 if (buttonFlag){
orlagilson 4:0302731434a5 181 buttonFlag=0;
orlagilson 4:0302731434a5 182 menu();
orlagilson 2:6b564e388747 183 }
orlagilson 2:6b564e388747 184 }
orlagilson 2:6b564e388747 185 }
orlagilson 2:6b564e388747 186
orlagilson 4:0302731434a5 187 void menu(){
orlagilson 4:0302731434a5 188 buttonleft.rise(&buttonPressed);
orlagilson 0:2fd314d76f37 189 while(1) {
orlagilson 2:6b564e388747 190 wait (0.1);
orlagilson 0:2fd314d76f37 191 lcd.normalMode(); //normal LCD colour mode
orlagilson 0:2fd314d76f37 192 lcd.setBrightness(0.5); //LCD backlight set to 50% brightness
orlagilson 0:2fd314d76f37 193 if (POT>(2.0/3.0)) {
orlagilson 0:2fd314d76f37 194 clearCells();
orlagilson 0:2fd314d76f37 195 lcd.printString("Temperature",10,1);
orlagilson 0:2fd314d76f37 196 lcd.printString(">",80,2);
orlagilson 0:2fd314d76f37 197 lcd.printString("Graph",0,5);
orlagilson 0:2fd314d76f37 198 lcd.printString("Current",43,5);
orlagilson 4:0302731434a5 199 if (buttonFlag){ //left button takes the user to the graph option
orlagilson 4:0302731434a5 200 buttonFlag=0;
orlagilson 0:2fd314d76f37 201 clearCells();
orlagilson 2:6b564e388747 202 tempGraph();
orlagilson 0:2fd314d76f37 203 }
orlagilson 0:2fd314d76f37 204 if (BUT2>0.9) { //right button takes the user to the current reading
orlagilson 0:2fd314d76f37 205 clearCells();
orlagilson 0:2fd314d76f37 206 readTemp();
orlagilson 0:2fd314d76f37 207 }
orlagilson 0:2fd314d76f37 208 }
orlagilson 0:2fd314d76f37 209 if ((POT>1.0/3.0)&&(POT<2.0/3.0)) {
orlagilson 0:2fd314d76f37 210 clearCells();
orlagilson 0:2fd314d76f37 211 lcd.printString("Pressure",20,1);
orlagilson 0:2fd314d76f37 212 lcd.printString("<",0,2);
orlagilson 0:2fd314d76f37 213 lcd.printString(">",80,2);
orlagilson 0:2fd314d76f37 214 lcd.printString("Graph",0,5);
orlagilson 0:2fd314d76f37 215 lcd.printString("Current",43,5);
orlagilson 4:0302731434a5 216 if (buttonFlag) {
orlagilson 4:0302731434a5 217 buttonFlag=0;
orlagilson 0:2fd314d76f37 218 clearCells();
orlagilson 2:6b564e388747 219 pressGraph();
orlagilson 0:2fd314d76f37 220 }
orlagilson 0:2fd314d76f37 221 if (BUT2>0.9) {
orlagilson 0:2fd314d76f37 222 clearCells();
orlagilson 0:2fd314d76f37 223 readPress();
orlagilson 0:2fd314d76f37 224 }
orlagilson 0:2fd314d76f37 225 }
orlagilson 0:2fd314d76f37 226 if (POT<(1.0/3.0)) {
orlagilson 0:2fd314d76f37 227 clearCells();
orlagilson 0:2fd314d76f37 228 lcd.printString("Light",30,1);
orlagilson 0:2fd314d76f37 229 lcd.printString("<",0,2);
orlagilson 0:2fd314d76f37 230 lcd.printString("Graph",0,5);
orlagilson 0:2fd314d76f37 231 lcd.printString("Current",43,5);
orlagilson 4:0302731434a5 232 if (buttonFlag) {
orlagilson 4:0302731434a5 233 buttonFlag=0;
orlagilson 0:2fd314d76f37 234 clearCells();
orlagilson 0:2fd314d76f37 235 //lightGraph();
orlagilson 0:2fd314d76f37 236 }
orlagilson 0:2fd314d76f37 237 if (BUT2>0.9) {
orlagilson 0:2fd314d76f37 238 clearCells();
orlagilson 0:2fd314d76f37 239 //readLight();
orlagilson 0:2fd314d76f37 240 }
orlagilson 0:2fd314d76f37 241 }
orlagilson 0:2fd314d76f37 242 }
orlagilson 0:2fd314d76f37 243 }
orlagilson 0:2fd314d76f37 244
orlagilson 0:2fd314d76f37 245 void clearCells ()
orlagilson 0:2fd314d76f37 246 {
orlagilson 0:2fd314d76f37 247 //loop through cells and clear
orlagilson 0:2fd314d76f37 248 for (int i=0; i<nx; i++) {
orlagilson 0:2fd314d76f37 249 for (int j=0; j<ny; j++) {
orlagilson 0:2fd314d76f37 250 lcd.clearPixel(i,j);
orlagilson 0:2fd314d76f37 251 }
orlagilson 0:2fd314d76f37 252 }
orlagilson 0:2fd314d76f37 253 lcd.refresh (); //must refresh to write buffer to display
orlagilson 0:2fd314d76f37 254 }
orlagilson 0:2fd314d76f37 255
orlagilson 1:1accd82f4281 256 int main(){
orlagilson 1:1accd82f4281 257 lcd.init();
orlagilson 1:1accd82f4281 258 bmp180.init();
orlagilson 1:1accd82f4281 259 menu();
orlagilson 0:2fd314d76f37 260 }