James Hughes JRH52

Dependencies:   C12832 FXOS8700Q Fader LM75B MMA7660 mbed reScale

Smart Thermometer + Spirit Level for the FRDMK64F Device

This program displays the temperature in Celsius and Fahrenheit and allows the user to set a "temperature alarm" that activates once the the temperature exceeds a temperature value specified by the user.

This program also displays graphical "spirit levels" showing degrees of rotaion along 3 axis.

The user can cycle between screens using sw2 and sw3 buttons, set the temperature alarm by pressing up and down on the joystick, control the volume of the alarm with the pot1 knob, and control the time value of the wait function by pressing left and right on the joystick.

Committer:
co838_jrh52
Date:
Fri Feb 26 20:30:11 2016 +0000
Revision:
3:8a1784883bde
Parent:
2:26a7c23e3513
more minor changes made

Who changed what in which revision?

UserRevisionLine numberNew contents of line
co838_jrh52 1:829f4ff1fd05 1 /*
co838_jrh52 1:829f4ff1fd05 2 * This program displays the temperature in Celsius and Fahrenheit
co838_jrh52 2:26a7c23e3513 3 * and allows the user to set a "temperature alarm" that activates
co838_jrh52 1:829f4ff1fd05 4 * once the the temperature exceeds a temperature value specified by the user.
co838_jrh52 3:8a1784883bde 5 * This program also displays graphical "spirit levels" showing
co838_jrh52 1:829f4ff1fd05 6 * degrees of rotaion along 3 axis.
co838_jrh52 2:26a7c23e3513 7 * The user can cycle between screens using sw2 and sw3 buttons,
co838_jrh52 1:829f4ff1fd05 8 * set the temperature alarm by pressing up and down on the joystick,
co838_jrh52 1:829f4ff1fd05 9 * control the volume of the alarm with the pot1 knob, and control the
co838_jrh52 2:26a7c23e3513 10 * time value of the wait function by pressing left and right on
co838_jrh52 1:829f4ff1fd05 11 * the joystick.
co838_jrh52 1:829f4ff1fd05 12 * screen 1: max temperature alarm
co838_jrh52 1:829f4ff1fd05 13 * screen 2: temperature in Celsius
co838_jrh52 1:829f4ff1fd05 14 * screen 3: temperature in Fahrenheit
co838_jrh52 1:829f4ff1fd05 15 * screen 4: spirit level
co838_jrh52 1:829f4ff1fd05 16 * screen 5: value for wait function
co838_jrh52 2:26a7c23e3513 17 *
co838_jrh52 1:829f4ff1fd05 18 */
co838_jrh52 1:829f4ff1fd05 19
co838_jrh52 1:829f4ff1fd05 20
co838_jrh52 0:55c7a177fdbb 21 #include "mbed.h"
co838_jrh52 1:829f4ff1fd05 22 #include "LM75B.h" /* temperature */
co838_jrh52 1:829f4ff1fd05 23 #include "C12832.h" /* LCD */
co838_jrh52 1:829f4ff1fd05 24 #include "MMA7660.h" /* for the accelerometer */
co838_jrh52 0:55c7a177fdbb 25 #include "reScale.h"
co838_jrh52 0:55c7a177fdbb 26
co838_jrh52 2:26a7c23e3513 27 //DigitalOut r_led (LED1); /* connections for RGB LED */
co838_jrh52 2:26a7c23e3513 28 //DigitalOut g_led (LED2);
co838_jrh52 2:26a7c23e3513 29 //DigitalOut b_led (LED3);
co838_jrh52 0:55c7a177fdbb 30
co838_jrh52 0:55c7a177fdbb 31 PwmOut spkr(D6); /* speaker */
co838_jrh52 0:55c7a177fdbb 32
co838_jrh52 0:55c7a177fdbb 33 //DigitalOut led(LED1); /* shield LEDs */
co838_jrh52 1:829f4ff1fd05 34 DigitalOut red(D5);
co838_jrh52 0:55c7a177fdbb 35 DigitalOut blue(PTC12);
co838_jrh52 1:829f4ff1fd05 36 DigitalOut green(D9);
co838_jrh52 0:55c7a177fdbb 37
co838_jrh52 0:55c7a177fdbb 38 InterruptIn sw2_int (PTC6); /* interrupts for on-board switches */
co838_jrh52 0:55c7a177fdbb 39 InterruptIn sw3_int (PTA4);
co838_jrh52 0:55c7a177fdbb 40 InterruptIn joy_up (PTB10);
co838_jrh52 0:55c7a177fdbb 41 InterruptIn joy_down (PTB11);
co838_jrh52 0:55c7a177fdbb 42 InterruptIn joy_left (PTC11);
co838_jrh52 0:55c7a177fdbb 43 InterruptIn joy_right (PTC10);
co838_jrh52 0:55c7a177fdbb 44 InterruptIn joy_fire (PTB23);
co838_jrh52 0:55c7a177fdbb 45 AnalogIn pot1 (A0);
co838_jrh52 0:55c7a177fdbb 46 AnalogIn pot2 (A1);
co838_jrh52 0:55c7a177fdbb 47
co838_jrh52 0:55c7a177fdbb 48 static volatile int sw2_trig; /* switches triggered? */
co838_jrh52 0:55c7a177fdbb 49 static volatile int sw3_trig;
co838_jrh52 0:55c7a177fdbb 50 static volatile int joy_up_trig;
co838_jrh52 0:55c7a177fdbb 51 static volatile int joy_down_trig;
co838_jrh52 1:829f4ff1fd05 52 static volatile int joy_right_trig;
co838_jrh52 1:829f4ff1fd05 53 static volatile int joy_left_trig;
co838_jrh52 0:55c7a177fdbb 54
co838_jrh52 1:829f4ff1fd05 55 /*
co838_jrh52 1:829f4ff1fd05 56 * interrupt handlers
co838_jrh52 1:829f4ff1fd05 57 */
co838_jrh52 0:55c7a177fdbb 58 void sw2_interrupt (void)
co838_jrh52 0:55c7a177fdbb 59 {
co838_jrh52 0:55c7a177fdbb 60 sw2_trig = 1;
co838_jrh52 0:55c7a177fdbb 61 }
co838_jrh52 0:55c7a177fdbb 62
co838_jrh52 0:55c7a177fdbb 63 void sw3_interrupt (void)
co838_jrh52 0:55c7a177fdbb 64 {
co838_jrh52 0:55c7a177fdbb 65 sw3_trig = 1;
co838_jrh52 0:55c7a177fdbb 66 }
co838_jrh52 0:55c7a177fdbb 67
co838_jrh52 0:55c7a177fdbb 68 void joy_up_interrupt (void)
co838_jrh52 0:55c7a177fdbb 69 {
co838_jrh52 0:55c7a177fdbb 70 joy_up_trig = 1;
co838_jrh52 0:55c7a177fdbb 71 }
co838_jrh52 0:55c7a177fdbb 72
co838_jrh52 0:55c7a177fdbb 73 void joy_down_interrupt (void)
co838_jrh52 0:55c7a177fdbb 74 {
co838_jrh52 0:55c7a177fdbb 75 joy_down_trig = 1;
co838_jrh52 0:55c7a177fdbb 76 }
co838_jrh52 0:55c7a177fdbb 77
co838_jrh52 1:829f4ff1fd05 78 void joy_right_interrupt (void)
co838_jrh52 1:829f4ff1fd05 79 {
co838_jrh52 1:829f4ff1fd05 80 joy_right_trig = 1;
co838_jrh52 1:829f4ff1fd05 81 }
co838_jrh52 1:829f4ff1fd05 82
co838_jrh52 1:829f4ff1fd05 83 void joy_left_interrupt (void)
co838_jrh52 1:829f4ff1fd05 84 {
co838_jrh52 1:829f4ff1fd05 85 joy_left_trig = 1;
co838_jrh52 1:829f4ff1fd05 86 }
co838_jrh52 1:829f4ff1fd05 87
co838_jrh52 1:829f4ff1fd05 88 // pins
co838_jrh52 1:829f4ff1fd05 89 C12832 lcd(D11, D13, D12, D7, D10); /* LCD */
co838_jrh52 1:829f4ff1fd05 90 LM75B sensor(D14,D15); /* temperature sensor */
co838_jrh52 0:55c7a177fdbb 91 MMA7660 MMA(D14, D15); /* accelerometer */
co838_jrh52 0:55c7a177fdbb 92
co838_jrh52 0:55c7a177fdbb 93 int main ()
co838_jrh52 0:55c7a177fdbb 94 {
co838_jrh52 1:829f4ff1fd05 95 double waitTime = 0.5; /* value for wait function */
co838_jrh52 1:829f4ff1fd05 96 int menu = 0; /* menu */
co838_jrh52 1:829f4ff1fd05 97 int maxTemp = 30; /* value for the temperature alarm */
co838_jrh52 1:829f4ff1fd05 98 double fahrenheit; /* for calculating fahrenheit */
co838_jrh52 2:26a7c23e3513 99
co838_jrh52 1:829f4ff1fd05 100 float x, y, z;
co838_jrh52 2:26a7c23e3513 101 int xInt;
co838_jrh52 2:26a7c23e3513 102 int yInt;
co838_jrh52 2:26a7c23e3513 103 int zInt;
co838_jrh52 2:26a7c23e3513 104
co838_jrh52 0:55c7a177fdbb 105 sw2_trig = 0;
co838_jrh52 0:55c7a177fdbb 106 sw3_trig = 0;
co838_jrh52 0:55c7a177fdbb 107 joy_up_trig = 0;
co838_jrh52 0:55c7a177fdbb 108 joy_down_trig = 0;
co838_jrh52 1:829f4ff1fd05 109 joy_right_trig = 0;
co838_jrh52 1:829f4ff1fd05 110
co838_jrh52 0:55c7a177fdbb 111 sw2_int.mode (PullUp);
co838_jrh52 0:55c7a177fdbb 112 sw2_int.fall (&sw2_interrupt);
co838_jrh52 1:829f4ff1fd05 113
co838_jrh52 0:55c7a177fdbb 114 sw3_int.mode (PullUp);
co838_jrh52 0:55c7a177fdbb 115 sw3_int.fall (&sw3_interrupt);
co838_jrh52 1:829f4ff1fd05 116
co838_jrh52 0:55c7a177fdbb 117 joy_up.mode (PullUp);
co838_jrh52 0:55c7a177fdbb 118 joy_up.fall (&joy_up_interrupt);
co838_jrh52 1:829f4ff1fd05 119
co838_jrh52 0:55c7a177fdbb 120 joy_down.mode (PullUp);
co838_jrh52 0:55c7a177fdbb 121 joy_down.fall (&joy_down_interrupt);
co838_jrh52 1:829f4ff1fd05 122
co838_jrh52 1:829f4ff1fd05 123 joy_right.mode (PullUp);
co838_jrh52 1:829f4ff1fd05 124 joy_right.fall (&joy_right_interrupt);
co838_jrh52 1:829f4ff1fd05 125
co838_jrh52 1:829f4ff1fd05 126 joy_left.mode (PullUp);
co838_jrh52 1:829f4ff1fd05 127 joy_left.fall (&joy_left_interrupt);
co838_jrh52 1:829f4ff1fd05 128
co838_jrh52 0:55c7a177fdbb 129 void tempAlarm();
co838_jrh52 0:55c7a177fdbb 130 void noAlarm();
co838_jrh52 0:55c7a177fdbb 131 void thermomCel(int n, int maxTemp);
co838_jrh52 2:26a7c23e3513 132 void spiritLev(int xYo, int yYo, int zYo);
co838_jrh52 1:829f4ff1fd05 133
co838_jrh52 1:829f4ff1fd05 134 /*
co838_jrh52 1:829f4ff1fd05 135 * main loop
co838_jrh52 1:829f4ff1fd05 136 */
co838_jrh52 0:55c7a177fdbb 137 while (1) {
co838_jrh52 1:829f4ff1fd05 138
co838_jrh52 2:26a7c23e3513 139 x = MMA.x();
co838_jrh52 2:26a7c23e3513 140 y = MMA.y();
co838_jrh52 2:26a7c23e3513 141 z = MMA.z();
co838_jrh52 2:26a7c23e3513 142
co838_jrh52 2:26a7c23e3513 143 float xMul = x * 10;
co838_jrh52 2:26a7c23e3513 144 float yMul = y * 10;
co838_jrh52 2:26a7c23e3513 145 float zMul = z * 10;
co838_jrh52 2:26a7c23e3513 146
co838_jrh52 2:26a7c23e3513 147 /*
co838_jrh52 2:26a7c23e3513 148 * used for graphical spirit levels
co838_jrh52 2:26a7c23e3513 149 */
co838_jrh52 2:26a7c23e3513 150 int xInt = static_cast<int>(xMul);
co838_jrh52 2:26a7c23e3513 151 int yInt = static_cast<int>(yMul);
co838_jrh52 2:26a7c23e3513 152 int zInt = static_cast<int>(zMul);
co838_jrh52 2:26a7c23e3513 153
co838_jrh52 2:26a7c23e3513 154 /*
co838_jrh52 2:26a7c23e3513 155 * change into degrees of rotation
co838_jrh52 2:26a7c23e3513 156 */
co838_jrh52 2:26a7c23e3513 157 int zTest = (10 - zInt) * 9;
co838_jrh52 2:26a7c23e3513 158 if (zTest<0) {
co838_jrh52 2:26a7c23e3513 159 zTest = 0;
co838_jrh52 1:829f4ff1fd05 160 }
co838_jrh52 2:26a7c23e3513 161 if (zTest>180) {
co838_jrh52 2:26a7c23e3513 162 zTest = 180;
co838_jrh52 1:829f4ff1fd05 163 }
co838_jrh52 2:26a7c23e3513 164
co838_jrh52 2:26a7c23e3513 165 int xTest = (xInt * 9) + 90;
co838_jrh52 2:26a7c23e3513 166 if (xTest<0) {
co838_jrh52 2:26a7c23e3513 167 xTest = 0;
co838_jrh52 1:829f4ff1fd05 168 }
co838_jrh52 2:26a7c23e3513 169 if (xTest>180) {
co838_jrh52 2:26a7c23e3513 170 xTest = 180;
co838_jrh52 1:829f4ff1fd05 171 }
co838_jrh52 2:26a7c23e3513 172
co838_jrh52 2:26a7c23e3513 173 int yTest = (yInt * 9) + 90;
co838_jrh52 2:26a7c23e3513 174 if (yTest<0) {
co838_jrh52 2:26a7c23e3513 175 yTest = 0;
co838_jrh52 1:829f4ff1fd05 176 }
co838_jrh52 2:26a7c23e3513 177 if (yTest>180) {
co838_jrh52 2:26a7c23e3513 178 yTest = 180;
co838_jrh52 2:26a7c23e3513 179 }
co838_jrh52 1:829f4ff1fd05 180
co838_jrh52 1:829f4ff1fd05 181 double tempDouble = static_cast<double>(sensor.temp());
co838_jrh52 2:26a7c23e3513 182 double fahrenheitPartOne = (tempDouble * 1.8) + 32; /* convert temperature to fahrenheit value */
co838_jrh52 3:8a1784883bde 183 int tempInt = static_cast<int>(sensor.temp()); /* convert temperature to int value (used for thermometer display)*/
co838_jrh52 1:829f4ff1fd05 184
co838_jrh52 1:829f4ff1fd05 185 /*
co838_jrh52 1:829f4ff1fd05 186 * blue LED if the temperature is lower than the alarm value
co838_jrh52 1:829f4ff1fd05 187 */
co838_jrh52 1:829f4ff1fd05 188 if(sensor.temp()<maxTemp) {
co838_jrh52 1:829f4ff1fd05 189 noAlarm();
co838_jrh52 0:55c7a177fdbb 190 }
co838_jrh52 2:26a7c23e3513 191
co838_jrh52 1:829f4ff1fd05 192 /*
co838_jrh52 2:26a7c23e3513 193 * orange LED if the temperature is lower than the alarm value within 2 degrees
co838_jrh52 1:829f4ff1fd05 194 */
co838_jrh52 1:829f4ff1fd05 195 if(sensor.temp()< maxTemp && sensor.temp()> maxTemp - 2) {
co838_jrh52 1:829f4ff1fd05 196 green = 0 & 0;
co838_jrh52 1:829f4ff1fd05 197 blue = 7 & 4;
co838_jrh52 1:829f4ff1fd05 198 red = 0 & 0;
co838_jrh52 1:829f4ff1fd05 199 }
co838_jrh52 1:829f4ff1fd05 200 /*
co838_jrh52 1:829f4ff1fd05 201 * alarm triggered if the temperature exceeds the temperature alarm value
co838_jrh52 1:829f4ff1fd05 202 */
co838_jrh52 1:829f4ff1fd05 203 if(sensor.temp()>maxTemp) {
co838_jrh52 1:829f4ff1fd05 204 tempAlarm();
co838_jrh52 0:55c7a177fdbb 205 }
co838_jrh52 2:26a7c23e3513 206
co838_jrh52 1:829f4ff1fd05 207 /*
co838_jrh52 2:26a7c23e3513 208 * display graphical thermometer and temperature alarm value
co838_jrh52 1:829f4ff1fd05 209 * on the first screen
co838_jrh52 1:829f4ff1fd05 210 */
co838_jrh52 1:829f4ff1fd05 211 if(menu==0) {
co838_jrh52 1:829f4ff1fd05 212 lcd.cls();
co838_jrh52 1:829f4ff1fd05 213 lcd.locate(0,3);
co838_jrh52 1:829f4ff1fd05 214 lcd.printf("Max Temp Alarm: %.1d", maxTemp);
co838_jrh52 3:8a1784883bde 215 thermomCel(tempInt, maxTemp);
co838_jrh52 1:829f4ff1fd05 216 wait(waitTime);
co838_jrh52 1:829f4ff1fd05 217 }
co838_jrh52 2:26a7c23e3513 218
co838_jrh52 1:829f4ff1fd05 219 /*
co838_jrh52 2:26a7c23e3513 220 * display graphical thermometer and temperature in celsius
co838_jrh52 2:26a7c23e3513 221 * on the second screen
co838_jrh52 1:829f4ff1fd05 222 */
co838_jrh52 1:829f4ff1fd05 223 if(menu==1) {
co838_jrh52 1:829f4ff1fd05 224 lcd.cls();
co838_jrh52 1:829f4ff1fd05 225 lcd.locate(0,3);
co838_jrh52 1:829f4ff1fd05 226 lcd.printf("Celsius: %.1f\n", sensor.temp());
co838_jrh52 3:8a1784883bde 227 thermomCel(tempInt, maxTemp);
co838_jrh52 1:829f4ff1fd05 228 wait(waitTime);
co838_jrh52 1:829f4ff1fd05 229 }
co838_jrh52 2:26a7c23e3513 230
co838_jrh52 1:829f4ff1fd05 231 /*
co838_jrh52 2:26a7c23e3513 232 * display graphical thermometer and temperature in fahrenheit
co838_jrh52 2:26a7c23e3513 233 * on the third screen
co838_jrh52 1:829f4ff1fd05 234 */
co838_jrh52 0:55c7a177fdbb 235 if(menu==2) {
co838_jrh52 1:829f4ff1fd05 236 lcd.cls();
co838_jrh52 1:829f4ff1fd05 237 lcd.locate(0,3);
co838_jrh52 2:26a7c23e3513 238 lcd.printf("Fahrenheit: %.1lf\n",fahrenheitPartOne); //changed this to fahrenheitPartOne
co838_jrh52 3:8a1784883bde 239 thermomCel(tempInt, maxTemp);
co838_jrh52 1:829f4ff1fd05 240 wait(waitTime);
co838_jrh52 0:55c7a177fdbb 241 }
co838_jrh52 2:26a7c23e3513 242
co838_jrh52 2:26a7c23e3513 243 /*
co838_jrh52 2:26a7c23e3513 244 * display spirit level
co838_jrh52 2:26a7c23e3513 245 * on the fourth screen
co838_jrh52 2:26a7c23e3513 246 */
co838_jrh52 0:55c7a177fdbb 247 if(menu==3) {
co838_jrh52 2:26a7c23e3513 248 lcd.cls();
co838_jrh52 2:26a7c23e3513 249 lcd.locate(0,3);
co838_jrh52 2:26a7c23e3513 250 spiritLev(xMul, yMul, zMul);
co838_jrh52 2:26a7c23e3513 251 lcd.locate(20,0);
co838_jrh52 3:8a1784883bde 252 lcd.printf("x: %.1d", xTest);
co838_jrh52 2:26a7c23e3513 253 lcd.locate(60,0);
co838_jrh52 3:8a1784883bde 254 lcd.printf("y: %.1d", yTest);
co838_jrh52 2:26a7c23e3513 255 lcd.locate(100,0);
co838_jrh52 3:8a1784883bde 256 lcd.printf("z: %.1d", zTest);
co838_jrh52 2:26a7c23e3513 257 wait(waitTime);
co838_jrh52 1:829f4ff1fd05 258 }
co838_jrh52 2:26a7c23e3513 259
co838_jrh52 2:26a7c23e3513 260 /*
co838_jrh52 2:26a7c23e3513 261 * display wait time value
co838_jrh52 2:26a7c23e3513 262 * on the fifth screen
co838_jrh52 2:26a7c23e3513 263 */
co838_jrh52 1:829f4ff1fd05 264 if(menu==4) {
co838_jrh52 1:829f4ff1fd05 265 lcd.cls();
co838_jrh52 1:829f4ff1fd05 266 lcd.locate(0,3);
co838_jrh52 2:26a7c23e3513 267 lcd.printf("Wait time value: %.1f", waitTime);
co838_jrh52 1:829f4ff1fd05 268 wait(waitTime);
co838_jrh52 1:829f4ff1fd05 269 }
co838_jrh52 1:829f4ff1fd05 270
co838_jrh52 1:829f4ff1fd05 271 /*
co838_jrh52 1:829f4ff1fd05 272 * pressing right trigger button cycles up through the screens
co838_jrh52 1:829f4ff1fd05 273 */
co838_jrh52 1:829f4ff1fd05 274 if (sw2_trig) {
co838_jrh52 1:829f4ff1fd05 275 menu++;
co838_jrh52 1:829f4ff1fd05 276 if(menu>4) {
co838_jrh52 1:829f4ff1fd05 277 menu = 4;
co838_jrh52 1:829f4ff1fd05 278 }
co838_jrh52 1:829f4ff1fd05 279 sw2_trig = 0;
co838_jrh52 0:55c7a177fdbb 280 }
co838_jrh52 2:26a7c23e3513 281
co838_jrh52 1:829f4ff1fd05 282 /*
co838_jrh52 1:829f4ff1fd05 283 * pressing left trigger button cycles down through the screens
co838_jrh52 1:829f4ff1fd05 284 */
co838_jrh52 0:55c7a177fdbb 285 if (sw3_trig) {
co838_jrh52 0:55c7a177fdbb 286 menu--;
co838_jrh52 0:55c7a177fdbb 287 if(menu<0) {
co838_jrh52 0:55c7a177fdbb 288 menu = 0;
co838_jrh52 0:55c7a177fdbb 289 }
co838_jrh52 0:55c7a177fdbb 290 sw3_trig = 0;
co838_jrh52 0:55c7a177fdbb 291 }
co838_jrh52 2:26a7c23e3513 292
co838_jrh52 1:829f4ff1fd05 293 /*
co838_jrh52 1:829f4ff1fd05 294 * pressing up on the joystick increases the temperature alarm value by 1
co838_jrh52 1:829f4ff1fd05 295 */
co838_jrh52 0:55c7a177fdbb 296 if(joy_up_trig) {
co838_jrh52 0:55c7a177fdbb 297 maxTemp = maxTemp + 1;
co838_jrh52 0:55c7a177fdbb 298 //set max value in here
co838_jrh52 0:55c7a177fdbb 299 joy_up_trig = 0;
co838_jrh52 0:55c7a177fdbb 300 }
co838_jrh52 2:26a7c23e3513 301
co838_jrh52 1:829f4ff1fd05 302 /*
co838_jrh52 1:829f4ff1fd05 303 * pressing down on the joystick decreases the temperature alarm value by 1
co838_jrh52 1:829f4ff1fd05 304 */
co838_jrh52 0:55c7a177fdbb 305 if(joy_down_trig) {
co838_jrh52 0:55c7a177fdbb 306 maxTemp = maxTemp - 1;
co838_jrh52 0:55c7a177fdbb 307 //set min value in here
co838_jrh52 0:55c7a177fdbb 308 joy_down_trig = 0;
co838_jrh52 0:55c7a177fdbb 309 }
co838_jrh52 2:26a7c23e3513 310
co838_jrh52 1:829f4ff1fd05 311 /*
co838_jrh52 1:829f4ff1fd05 312 * pressing right on the joystick increases the wait value value by 0.25
co838_jrh52 1:829f4ff1fd05 313 */
co838_jrh52 1:829f4ff1fd05 314 if(joy_right_trig) {
co838_jrh52 1:829f4ff1fd05 315 waitTime = waitTime + 0.25;
co838_jrh52 2:26a7c23e3513 316 //set max value in here
co838_jrh52 1:829f4ff1fd05 317 joy_right_trig = 0;
co838_jrh52 1:829f4ff1fd05 318 }
co838_jrh52 2:26a7c23e3513 319
co838_jrh52 1:829f4ff1fd05 320 /*
co838_jrh52 1:829f4ff1fd05 321 * pressing left on the joystick decreases the wait value value by 0.25
co838_jrh52 1:829f4ff1fd05 322 */
co838_jrh52 1:829f4ff1fd05 323 if(joy_left_trig) {
co838_jrh52 1:829f4ff1fd05 324 waitTime = waitTime - 0.25;
co838_jrh52 1:829f4ff1fd05 325 if(waitTime<0.25) {
co838_jrh52 1:829f4ff1fd05 326 waitTime = 0.25;
co838_jrh52 2:26a7c23e3513 327 }
co838_jrh52 1:829f4ff1fd05 328 joy_left_trig = 0;
co838_jrh52 1:829f4ff1fd05 329 }
co838_jrh52 0:55c7a177fdbb 330
co838_jrh52 0:55c7a177fdbb 331 }
co838_jrh52 1:829f4ff1fd05 332
co838_jrh52 1:829f4ff1fd05 333 }
co838_jrh52 1:829f4ff1fd05 334 /*
co838_jrh52 1:829f4ff1fd05 335 * turn the LED red and make an alarm noise
co838_jrh52 1:829f4ff1fd05 336 * pot1 controls the speaker volume
co838_jrh52 1:829f4ff1fd05 337 */
co838_jrh52 1:829f4ff1fd05 338 void tempAlarm()
co838_jrh52 1:829f4ff1fd05 339 {
co838_jrh52 1:829f4ff1fd05 340 float volume = pot1;
co838_jrh52 1:829f4ff1fd05 341
co838_jrh52 1:829f4ff1fd05 342 for (float i=2000.0; i<5000.0; i+=100) {
co838_jrh52 1:829f4ff1fd05 343 spkr.period(5.0/i);
co838_jrh52 1:829f4ff1fd05 344 spkr=volume;
co838_jrh52 1:829f4ff1fd05 345 wait(0.01);
co838_jrh52 1:829f4ff1fd05 346 }
co838_jrh52 1:829f4ff1fd05 347
co838_jrh52 1:829f4ff1fd05 348 green = 1;
co838_jrh52 1:829f4ff1fd05 349 blue = 1;
co838_jrh52 1:829f4ff1fd05 350 red = 0;
co838_jrh52 0:55c7a177fdbb 351 }
co838_jrh52 0:55c7a177fdbb 352
co838_jrh52 1:829f4ff1fd05 353 /*
co838_jrh52 1:829f4ff1fd05 354 * turns the LED blue and stops the speaker
co838_jrh52 1:829f4ff1fd05 355 */
co838_jrh52 1:829f4ff1fd05 356 void noAlarm()
co838_jrh52 0:55c7a177fdbb 357 {
co838_jrh52 1:829f4ff1fd05 358 spkr=0;
co838_jrh52 1:829f4ff1fd05 359 green = 1;
co838_jrh52 1:829f4ff1fd05 360 blue = 0;
co838_jrh52 1:829f4ff1fd05 361 red = 1;
co838_jrh52 0:55c7a177fdbb 362 }
co838_jrh52 0:55c7a177fdbb 363
co838_jrh52 1:829f4ff1fd05 364 /*
co838_jrh52 1:829f4ff1fd05 365 * display the graphical thermometer
co838_jrh52 1:829f4ff1fd05 366 */
co838_jrh52 0:55c7a177fdbb 367 void thermomCel(int n, int maxTemp)
co838_jrh52 0:55c7a177fdbb 368 {
co838_jrh52 2:26a7c23e3513 369 lcd.rect(0, 25, 127, 30, 50);
co838_jrh52 1:829f4ff1fd05 370 lcd.fillrect(60, 25, 60 + n, 30, 50);
co838_jrh52 1:829f4ff1fd05 371 lcd.circle(60, 19, 2, 50);
co838_jrh52 1:829f4ff1fd05 372 lcd.line(60, 25, 60, 23, 50);
co838_jrh52 1:829f4ff1fd05 373 lcd.line(60 + n, 25, 60 + n, 20, 50);
co838_jrh52 1:829f4ff1fd05 374 lcd.line(60 + maxTemp, 25, 60 + maxTemp, 20, 50);
co838_jrh52 0:55c7a177fdbb 375 }
co838_jrh52 0:55c7a177fdbb 376
co838_jrh52 2:26a7c23e3513 377 /*
co838_jrh52 2:26a7c23e3513 378 * display the spirit level
co838_jrh52 2:26a7c23e3513 379 */
co838_jrh52 2:26a7c23e3513 380 void spiritLev(int xYo, int yYo, int zYo)
co838_jrh52 1:829f4ff1fd05 381 {
co838_jrh52 2:26a7c23e3513 382 lcd.rect(20, 10, 30, 30, 50);
co838_jrh52 2:26a7c23e3513 383 lcd.fillrect(20, 20, 30, 20 - xYo, 50);
co838_jrh52 2:26a7c23e3513 384 lcd.rect(60, 10, 70, 30, 50);
co838_jrh52 2:26a7c23e3513 385 lcd.fillrect(60, 20, 70, 20 - yYo, 50);
co838_jrh52 2:26a7c23e3513 386 lcd.rect(100, 10, 110, 30, 50);
co838_jrh52 2:26a7c23e3513 387 lcd.fillrect(100, 30 - (10 - zYo), 110, 30, 50);
co838_jrh52 2:26a7c23e3513 388 //lcd.fillrect(60, 25, 60 + n, 30, 50);
co838_jrh52 1:829f4ff1fd05 389 }