![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Level 2 Project Range Device
Dependencies: N5110 SDFileSystem SRF02 TMP102 mbed
Fork of Ranger by
main.cpp@7:14cfb0df30e6, 2016-04-25 (annotated)
- Committer:
- el15pjt
- Date:
- Mon Apr 25 10:08:05 2016 +0000
- Revision:
- 7:14cfb0df30e6
- Parent:
- 6:b464a8a94d91
- Child:
- 8:fe6ebe807b9d
BUZZER TO IMPLEMENT AND AVERAGE;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el15pjt | 7:14cfb0df30e6 | 1 | |
el15pjt | 7:14cfb0df30e6 | 2 | /** |
el15pjt | 7:14cfb0df30e6 | 3 | @file main.cpp |
el15pjt | 7:14cfb0df30e6 | 4 | @brief Program implementation |
el15pjt | 0:0b180348c7e4 | 5 | */ |
el15pjt | 0:0b180348c7e4 | 6 | |
el15pjt | 7:14cfb0df30e6 | 7 | #include "main.h" |
el15pjt | 7:14cfb0df30e6 | 8 | #include "SDFileSystem.h" |
el15pjt | 7:14cfb0df30e6 | 9 | Serial serial(USBTX, USBRX); // for PC debug |
el15pjt | 4:673930f04866 | 10 | |
el15pjt | 0:0b180348c7e4 | 11 | |
el15pjt | 0:0b180348c7e4 | 12 | int main() |
el15pjt | 0:0b180348c7e4 | 13 | { |
el15pjt | 7:14cfb0df30e6 | 14 | setup(); |
el15pjt | 7:14cfb0df30e6 | 15 | lcd.init(); // Initiate LCD |
el15pjt | 7:14cfb0df30e6 | 16 | /* |
el15pjt | 7:14cfb0df30e6 | 17 | sprintf(buffer,"ELEC 2645"); |
el15pjt | 7:14cfb0df30e6 | 18 | sprintf(buffer1,"Project Ranger"); |
el15pjt | 7:14cfb0df30e6 | 19 | sprintf(buffer2,"Phil Thompson"); |
el15pjt | 7:14cfb0df30e6 | 20 | sprintf(buffer3,"SID 200971914 "); |
el15pjt | 7:14cfb0df30e6 | 21 | lcd.printString(buffer,0,0); |
el15pjt | 7:14cfb0df30e6 | 22 | lcd.printString(buffer1,0,1); |
el15pjt | 7:14cfb0df30e6 | 23 | lcd.printString(buffer2,0,2); |
el15pjt | 7:14cfb0df30e6 | 24 | lcd.printString(buffer3,0,3); |
el15pjt | 7:14cfb0df30e6 | 25 | wait (3); |
el15pjt | 7:14cfb0df30e6 | 26 | */ |
el15pjt | 7:14cfb0df30e6 | 27 | /* |
el15pjt | 7:14cfb0df30e6 | 28 | serial.baud(115200); // full-speed! |
el15pjt | 7:14cfb0df30e6 | 29 | serial.printf("#### SD Card Example #####\n"); |
el15pjt | 7:14cfb0df30e6 | 30 | FILE *fp; // this is our file pointer |
el15pjt | 7:14cfb0df30e6 | 31 | wait(1); |
el15pjt | 7:14cfb0df30e6 | 32 | { |
el15pjt | 7:14cfb0df30e6 | 33 | /////////////////////// Reading from file example //////////////////////// |
el15pjt | 7:14cfb0df30e6 | 34 | |
el15pjt | 7:14cfb0df30e6 | 35 | // now open file for reading...note the 'r' |
el15pjt | 7:14cfb0df30e6 | 36 | fp = fopen("/sd/settings.txt", "r"); |
el15pjt | 7:14cfb0df30e6 | 37 | if (fp == NULL) { // if it can't open the file then print error message |
el15pjt | 7:14cfb0df30e6 | 38 | serial.printf("Error! Unable to open file!\n"); |
el15pjt | 7:14cfb0df30e6 | 39 | } else { |
el15pjt | 7:14cfb0df30e6 | 40 | serial.printf("Reading file....\n"); |
el15pjt | 7:14cfb0df30e6 | 41 | int r1; |
el15pjt | 7:14cfb0df30e6 | 42 | int r2; |
el15pjt | 7:14cfb0df30e6 | 43 | int r3; |
el15pjt | 7:14cfb0df30e6 | 44 | int r4; |
el15pjt | 7:14cfb0df30e6 | 45 | int r5; |
el15pjt | 7:14cfb0df30e6 | 46 | int r6; |
el15pjt | 7:14cfb0df30e6 | 47 | int r7; |
el15pjt | 7:14cfb0df30e6 | 48 | int offset; // create suitable variables to store the data in the file |
el15pjt | 7:14cfb0df30e6 | 49 | float bright; |
el15pjt | 7:14cfb0df30e6 | 50 | float value; |
el15pjt | 7:14cfb0df30e6 | 51 | int i; |
el15pjt | 7:14cfb0df30e6 | 52 | |
el15pjt | 7:14cfb0df30e6 | 53 | // in this example, we keep reading (using fscanf) until we reach |
el15pjt | 7:14cfb0df30e6 | 54 | // the 'end of file'. Note we use the address operator & to write |
el15pjt | 7:14cfb0df30e6 | 55 | // to the variables. Also the format of the string must match what |
el15pjt | 7:14cfb0df30e6 | 56 | // is in the file |
el15pjt | 7:14cfb0df30e6 | 57 | while (fscanf(fp, "%d,%f", &i, &value) != EOF) { |
el15pjt | 7:14cfb0df30e6 | 58 | serial.printf("%d,%f\n",i,value); |
el15pjt | 7:14cfb0df30e6 | 59 | } |
el15pjt | 7:14cfb0df30e6 | 60 | serial.printf("Done.\n"); |
el15pjt | 7:14cfb0df30e6 | 61 | fclose(fp); // ensure you close the file after reading |
el15pjt | 7:14cfb0df30e6 | 62 | } |
el15pjt | 7:14cfb0df30e6 | 63 | } |
el15pjt | 7:14cfb0df30e6 | 64 | */ |
el15pjt | 0:0b180348c7e4 | 65 | while(1) { |
el15pjt | 4:673930f04866 | 66 | |
el15pjt | 5:083d484e95a1 | 67 | if (g_sw1_flag) { |
el15pjt | 5:083d484e95a1 | 68 | g_sw1_flag = 0; |
el15pjt | 5:083d484e95a1 | 69 | page = 0; |
el15pjt | 5:083d484e95a1 | 70 | subpage = 0; |
el15pjt | 6:b464a8a94d91 | 71 | lcd.clear(); |
el15pjt | 5:083d484e95a1 | 72 | menu(); |
el15pjt | 2:329597081c06 | 73 | } |
el15pjt | 5:083d484e95a1 | 74 | |
el15pjt | 3:8782b8b8658b | 75 | if (g_timer_flag_srf02) { |
el15pjt | 3:8782b8b8658b | 76 | g_timer_flag_srf02 = 0; // if it has, clear the flag |
el15pjt | 5:083d484e95a1 | 77 | if (units == METRIC) { |
el15pjt | 5:083d484e95a1 | 78 | distance = srf02.getDistanceCm(); |
el15pjt | 7:14cfb0df30e6 | 79 | distance = distance-(offset*c); |
el15pjt | 5:083d484e95a1 | 80 | } else { |
el15pjt | 5:083d484e95a1 | 81 | distance = srf02.getDistannceInch(); |
el15pjt | 7:14cfb0df30e6 | 82 | distance = distance -(offset*c); |
el15pjt | 5:083d484e95a1 | 83 | } |
el15pjt | 7:14cfb0df30e6 | 84 | |
el15pjt | 7:14cfb0df30e6 | 85 | |
el15pjt | 7:14cfb0df30e6 | 86 | |
el15pjt | 7:14cfb0df30e6 | 87 | |
el15pjt | 7:14cfb0df30e6 | 88 | |
el15pjt | 7:14cfb0df30e6 | 89 | |
el15pjt | 7:14cfb0df30e6 | 90 | |
el15pjt | 7:14cfb0df30e6 | 91 | |
el15pjt | 7:14cfb0df30e6 | 92 | if (d == 9) { |
el15pjt | 7:14cfb0df30e6 | 93 | d = 0; |
el15pjt | 7:14cfb0df30e6 | 94 | } else { |
el15pjt | 7:14cfb0df30e6 | 95 | d++; |
el15pjt | 7:14cfb0df30e6 | 96 | } |
el15pjt | 7:14cfb0df30e6 | 97 | myarray[d] = distance; |
el15pjt | 7:14cfb0df30e6 | 98 | totaldistance = 0; |
el15pjt | 7:14cfb0df30e6 | 99 | for (i = 0; i < 10; i++) { |
el15pjt | 7:14cfb0df30e6 | 100 | totaldistance = totaldistance+myarray[i]; |
el15pjt | 7:14cfb0df30e6 | 101 | } |
el15pjt | 7:14cfb0df30e6 | 102 | avgdistance = totaldistance; |
el15pjt | 0:0b180348c7e4 | 103 | } |
el15pjt | 7:14cfb0df30e6 | 104 | |
el15pjt | 7:14cfb0df30e6 | 105 | |
el15pjt | 7:14cfb0df30e6 | 106 | |
el15pjt | 7:14cfb0df30e6 | 107 | |
el15pjt | 7:14cfb0df30e6 | 108 | |
el15pjt | 7:14cfb0df30e6 | 109 | |
el15pjt | 7:14cfb0df30e6 | 110 | |
el15pjt | 7:14cfb0df30e6 | 111 | |
el15pjt | 5:083d484e95a1 | 112 | setalert(); |
el15pjt | 3:8782b8b8658b | 113 | lcdoutput(); |
el15pjt | 7:14cfb0df30e6 | 114 | setbuzzer(); |
el15pjt | 3:8782b8b8658b | 115 | setleds(); |
el15pjt | 4:673930f04866 | 116 | sleep(); |
el15pjt | 0:0b180348c7e4 | 117 | } |
el15pjt | 0:0b180348c7e4 | 118 | } |
el15pjt | 0:0b180348c7e4 | 119 | |
el15pjt | 3:8782b8b8658b | 120 | void lcdoutput() |
el15pjt | 3:8782b8b8658b | 121 | { |
el15pjt | 7:14cfb0df30e6 | 122 | /** |
el15pjt | 7:14cfb0df30e6 | 123 | Function called to print to the LCD display |
el15pjt | 7:14cfb0df30e6 | 124 | @param i used to scale the max distaance to the width of the screen |
el15pjt | 7:14cfb0df30e6 | 125 | @param distance Distance read from sensor to be dispayed |
el15pjt | 7:14cfb0df30e6 | 126 | @param distbar used to adjust how far along the screen the bar is to go acorrding to distance |
el15pjt | 7:14cfb0df30e6 | 127 | */ |
el15pjt | 7:14cfb0df30e6 | 128 | |
el15pjt | 7:14cfb0df30e6 | 129 | // if alert == 0 no need to display range path is clear |
el15pjt | 6:b464a8a94d91 | 130 | if (alert == 0) { |
el15pjt | 7:14cfb0df30e6 | 131 | if (g_timer_flag_standby) { |
el15pjt | 7:14cfb0df30e6 | 132 | g_timer_flag_standby = 0; |
el15pjt | 7:14cfb0df30e6 | 133 | T = tmp102.get_temperature(); |
el15pjt | 7:14cfb0df30e6 | 134 | standby++; |
el15pjt | 7:14cfb0df30e6 | 135 | if (standby >3) { |
el15pjt | 7:14cfb0df30e6 | 136 | standby = 3; |
el15pjt | 7:14cfb0df30e6 | 137 | } |
el15pjt | 7:14cfb0df30e6 | 138 | } |
el15pjt | 7:14cfb0df30e6 | 139 | |
el15pjt | 7:14cfb0df30e6 | 140 | switch (standby) { |
el15pjt | 7:14cfb0df30e6 | 141 | case 1: |
el15pjt | 7:14cfb0df30e6 | 142 | lcd.clear(); |
el15pjt | 7:14cfb0df30e6 | 143 | sprintf(buffer,"**PATH CLEAR**"); |
el15pjt | 7:14cfb0df30e6 | 144 | lcd.printString(buffer,0,0); |
el15pjt | 7:14cfb0df30e6 | 145 | lcd.refresh(); |
el15pjt | 7:14cfb0df30e6 | 146 | break; |
el15pjt | 7:14cfb0df30e6 | 147 | case 2: |
el15pjt | 7:14cfb0df30e6 | 148 | lcd.clear(); |
el15pjt | 7:14cfb0df30e6 | 149 | sprintf(buffer3,"TEMP = %.2f",T); |
el15pjt | 7:14cfb0df30e6 | 150 | sprintf(buffer2,"TEMPERATER"); |
el15pjt | 7:14cfb0df30e6 | 151 | lcd.printString(buffer3,4,3); |
el15pjt | 7:14cfb0df30e6 | 152 | lcd.printString(buffer2,12,2); |
el15pjt | 7:14cfb0df30e6 | 153 | break; |
el15pjt | 7:14cfb0df30e6 | 154 | case 3: |
el15pjt | 7:14cfb0df30e6 | 155 | lcd.clear(); |
el15pjt | 7:14cfb0df30e6 | 156 | sprintf(buffer3,"TEMP = %.2f",T); |
el15pjt | 7:14cfb0df30e6 | 157 | sprintf(buffer2,"TEMPERATER"); |
el15pjt | 7:14cfb0df30e6 | 158 | lcd.refresh(); |
el15pjt | 7:14cfb0df30e6 | 159 | lcd.printString(buffer3,4,3); |
el15pjt | 7:14cfb0df30e6 | 160 | lcd.printString(buffer2,12,2); |
el15pjt | 7:14cfb0df30e6 | 161 | lcd.setBrightness(0); |
el15pjt | 7:14cfb0df30e6 | 162 | break; |
el15pjt | 7:14cfb0df30e6 | 163 | } |
el15pjt | 7:14cfb0df30e6 | 164 | } |
el15pjt | 7:14cfb0df30e6 | 165 | |
el15pjt | 7:14cfb0df30e6 | 166 | //If alert isn't 0 then the distance is to be dispayed alonng with the the distance bar |
el15pjt | 7:14cfb0df30e6 | 167 | else { |
el15pjt | 7:14cfb0df30e6 | 168 | lcd.setBrightness(bright); |
el15pjt | 7:14cfb0df30e6 | 169 | standby =0; |
el15pjt | 6:b464a8a94d91 | 170 | lcd.clear(); |
el15pjt | 3:8782b8b8658b | 171 | |
el15pjt | 7:14cfb0df30e6 | 172 | if (units == METRIC) { |
el15pjt | 7:14cfb0df30e6 | 173 | sprintf(buffer,"%i Cm",distance); |
el15pjt | 7:14cfb0df30e6 | 174 | sprintf(buffer1,"****RANGE!****"); |
el15pjt | 7:14cfb0df30e6 | 175 | sprintf(buffer2,"DISTANCE"); |
el15pjt | 7:14cfb0df30e6 | 176 | sprintf(buffer3,"%0.2f",avgdistance); |
el15pjt | 7:14cfb0df30e6 | 177 | sprintf(buffer4,"Menu"); |
el15pjt | 3:8782b8b8658b | 178 | |
el15pjt | 5:083d484e95a1 | 179 | } else { |
el15pjt | 7:14cfb0df30e6 | 180 | sprintf(buffer,"%i Inches",distance); |
el15pjt | 7:14cfb0df30e6 | 181 | sprintf(buffer1,"****RANGE!****"); |
el15pjt | 7:14cfb0df30e6 | 182 | sprintf(buffer2,"***DISTANCE***"); |
el15pjt | 7:14cfb0df30e6 | 183 | sprintf(buffer2,"Menu"); |
el15pjt | 5:083d484e95a1 | 184 | } |
el15pjt | 7:14cfb0df30e6 | 185 | lcd.printString(buffer,25,2); |
el15pjt | 6:b464a8a94d91 | 186 | lcd.printString(buffer1,0,0); |
el15pjt | 7:14cfb0df30e6 | 187 | lcd.printString(buffer2,16,1); |
el15pjt | 7:14cfb0df30e6 | 188 | lcd.printString(buffer4,0,5); |
el15pjt | 7:14cfb0df30e6 | 189 | lcd.printString(buffer3,0,3); |
el15pjt | 7:14cfb0df30e6 | 190 | |
el15pjt | 7:14cfb0df30e6 | 191 | float i = (r7/84); |
el15pjt | 7:14cfb0df30e6 | 192 | float distbar = (distance*i); |
el15pjt | 6:b464a8a94d91 | 193 | //drawRect(int x0,int y0,int width,int height,int fill); |
el15pjt | 7:14cfb0df30e6 | 194 | lcd.drawRect(0,29,distbar,7,1); // MOVE BAR UP!!!!!!!!!!!!!!!!!!!!!!!!! |
el15pjt | 6:b464a8a94d91 | 195 | lcd.refresh(); |
el15pjt | 6:b464a8a94d91 | 196 | |
el15pjt | 5:083d484e95a1 | 197 | } |
el15pjt | 3:8782b8b8658b | 198 | |
el15pjt | 3:8782b8b8658b | 199 | } |
el15pjt | 3:8782b8b8658b | 200 | |
el15pjt | 3:8782b8b8658b | 201 | void setalert() |
el15pjt | 3:8782b8b8658b | 202 | { |
el15pjt | 7:14cfb0df30e6 | 203 | /** A fuction used to determin the alert level given a range with the use of IF statments |
el15pjt | 7:14cfb0df30e6 | 204 | @param distance The distance read from sensor |
el15pjt | 7:14cfb0df30e6 | 205 | @param alert The level that distance falls with in 0 -7 |
el15pjt | 7:14cfb0df30e6 | 206 | @returns alert |
el15pjt | 7:14cfb0df30e6 | 207 | */ |
el15pjt | 7:14cfb0df30e6 | 208 | |
el15pjt | 7:14cfb0df30e6 | 209 | if (distance >= (r6*c) && distance < (r7*c)) { // r6 150 and r7 200 |
el15pjt | 7:14cfb0df30e6 | 210 | alert = 1; /// alert 1 distance between preset 150Cm to 200Cm |
el15pjt | 7:14cfb0df30e6 | 211 | } else if (distance >= (r5*c) && distance < (r6*c)) { |
el15pjt | 7:14cfb0df30e6 | 212 | alert = 2; /// alert 2 when between preset 90Cm to 150Cm |
el15pjt | 7:14cfb0df30e6 | 213 | } else if (distance >= (r4*c) && distance < (r5*c)) { |
el15pjt | 7:14cfb0df30e6 | 214 | alert = 3; /// alert 3 when distance between 60Cm to 90Cm |
el15pjt | 7:14cfb0df30e6 | 215 | } else if (distance >= (r3*c) && distance < (r4*c)) { |
el15pjt | 7:14cfb0df30e6 | 216 | alert = 4; /// alert 4 when distance between 40Cm and 60Cm |
el15pjt | 7:14cfb0df30e6 | 217 | } else if (distance >= (r2*c) && distance < (r3*c)) { |
el15pjt | 7:14cfb0df30e6 | 218 | alert = 5; ///alert 5 when distance between 20Cm and 40m |
el15pjt | 7:14cfb0df30e6 | 219 | } else if (distance >= (r1*c) && distance <= (r2*c)) { //r1 3 and r2 20 |
el15pjt | 7:14cfb0df30e6 | 220 | alert = 6; ///alert 6 when distance between 1 and 20 |
el15pjt | 7:14cfb0df30e6 | 221 | } else if (distance <=(r1*c)) { |
el15pjt | 7:14cfb0df30e6 | 222 | alert = 7; ///alert 7 when distance below 1Cm |
el15pjt | 3:8782b8b8658b | 223 | } else { |
el15pjt | 7:14cfb0df30e6 | 224 | alert = 0; /// alert 0 all else |
el15pjt | 3:8782b8b8658b | 225 | } |
el15pjt | 2:329597081c06 | 226 | } |
el15pjt | 2:329597081c06 | 227 | |
el15pjt | 3:8782b8b8658b | 228 | void setleds() |
el15pjt | 3:8782b8b8658b | 229 | { |
el15pjt | 7:14cfb0df30e6 | 230 | if (alert ==7) { |
el15pjt | 5:083d484e95a1 | 231 | if (g_timer_flag_led) { |
el15pjt | 5:083d484e95a1 | 232 | g_timer_flag_led = 0; // if it has, clear the flag |
el15pjt | 3:8782b8b8658b | 233 | rr_led = !rr_led; |
el15pjt | 5:083d484e95a1 | 234 | gg_led = !gg_led; |
el15pjt | 5:083d484e95a1 | 235 | a_led = !a_led; |
el15pjt | 5:083d484e95a1 | 236 | } |
el15pjt | 5:083d484e95a1 | 237 | } else if(Alertlevel[alert].fa_led == HIGH) { |
el15pjt | 5:083d484e95a1 | 238 | if (g_timer_flag_led) { |
el15pjt | 5:083d484e95a1 | 239 | g_timer_flag_led = 0; // if it has, clear the flag |
el15pjt | 5:083d484e95a1 | 240 | a_led = !a_led; |
el15pjt | 5:083d484e95a1 | 241 | } |
el15pjt | 5:083d484e95a1 | 242 | } else if (Alertlevel[alert].frr_led == HIGH) { |
el15pjt | 5:083d484e95a1 | 243 | if (g_timer_flag_led) { |
el15pjt | 5:083d484e95a1 | 244 | g_timer_flag_led = 0; // if it has, clear the flag |
el15pjt | 5:083d484e95a1 | 245 | rr_led = !rr_led; |
el15pjt | 5:083d484e95a1 | 246 | } |
el15pjt | 5:083d484e95a1 | 247 | } else if(Alertlevel[alert].fgg_led == HIGH) { |
el15pjt | 5:083d484e95a1 | 248 | if (g_timer_flag_led) { |
el15pjt | 5:083d484e95a1 | 249 | g_timer_flag_led = 0; // if it has, clear the flag |
el15pjt | 5:083d484e95a1 | 250 | gg_led = !gg_led; |
el15pjt | 3:8782b8b8658b | 251 | } |
el15pjt | 3:8782b8b8658b | 252 | } else { |
el15pjt | 3:8782b8b8658b | 253 | rr_led = Alertlevel[alert].srr_led; |
el15pjt | 5:083d484e95a1 | 254 | a_led = Alertlevel[alert].sa_led; |
el15pjt | 5:083d484e95a1 | 255 | gg_led = Alertlevel[alert].sgg_led; |
el15pjt | 3:8782b8b8658b | 256 | } |
el15pjt | 3:8782b8b8658b | 257 | |
el15pjt | 5:083d484e95a1 | 258 | } |
el15pjt | 7:14cfb0df30e6 | 259 | |
el15pjt | 5:083d484e95a1 | 260 | void setbuzzer() |
el15pjt | 5:083d484e95a1 | 261 | { |
el15pjt | 7:14cfb0df30e6 | 262 | int beat; |
el15pjt | 7:14cfb0df30e6 | 263 | /** |
el15pjt | 7:14cfb0df30e6 | 264 | control the PWM to drive the buzzer |
el15pjt | 7:14cfb0df30e6 | 265 | @param buzzer.period frequncy 1KHz |
el15pjt | 7:14cfb0df30e6 | 266 | @param buzzer duty cycle equal on/off max volume |
el15pjt | 7:14cfb0df30e6 | 267 | @param Alertlevel[alert].toneon controls how long the tone will last depending on alert |
el15pjt | 7:14cfb0df30e6 | 268 | */ |
el15pjt | 5:083d484e95a1 | 269 | if (g_timer_flag_tone) { |
el15pjt | 7:14cfb0df30e6 | 270 | g_timer_flag_tone = 1; |
el15pjt | 7:14cfb0df30e6 | 271 | if (beat == 10) { |
el15pjt | 7:14cfb0df30e6 | 272 | beat = 0; |
el15pjt | 7:14cfb0df30e6 | 273 | } else { |
el15pjt | 7:14cfb0df30e6 | 274 | beat++; |
el15pjt | 7:14cfb0df30e6 | 275 | } |
el15pjt | 7:14cfb0df30e6 | 276 | |
el15pjt | 7:14cfb0df30e6 | 277 | |
el15pjt | 7:14cfb0df30e6 | 278 | |
el15pjt | 7:14cfb0df30e6 | 279 | if (Alertlevel[alert].toneon < beat) { |
el15pjt | 7:14cfb0df30e6 | 280 | buzzer.period (1/10000); |
el15pjt | 7:14cfb0df30e6 | 281 | buzzer = 0.5; |
el15pjt | 7:14cfb0df30e6 | 282 | } else { |
el15pjt | 7:14cfb0df30e6 | 283 | buzzer = 0.0; |
el15pjt | 7:14cfb0df30e6 | 284 | } |
el15pjt | 7:14cfb0df30e6 | 285 | |
el15pjt | 7:14cfb0df30e6 | 286 | |
el15pjt | 3:8782b8b8658b | 287 | } |
el15pjt | 3:8782b8b8658b | 288 | } |
el15pjt | 3:8782b8b8658b | 289 | |
el15pjt | 3:8782b8b8658b | 290 | void backlight () |
el15pjt | 3:8782b8b8658b | 291 | { |
el15pjt | 3:8782b8b8658b | 292 | if (bright == 1.0) { |
el15pjt | 3:8782b8b8658b | 293 | bright = 0; |
el15pjt | 3:8782b8b8658b | 294 | } else { |
el15pjt | 3:8782b8b8658b | 295 | bright += 0.2; |
el15pjt | 3:8782b8b8658b | 296 | } |
el15pjt | 3:8782b8b8658b | 297 | lcd.setBrightness(bright); |
el15pjt | 3:8782b8b8658b | 298 | } |
el15pjt | 3:8782b8b8658b | 299 | |
el15pjt | 3:8782b8b8658b | 300 | void sw2_isr() |
el15pjt | 3:8782b8b8658b | 301 | { |
el15pjt | 7:14cfb0df30e6 | 302 | g_sw2_flag = 1; /** set flag in ISR by button 2 @param g_sw2_flag 0 or 1*/ |
el15pjt | 3:8782b8b8658b | 303 | } |
el15pjt | 3:8782b8b8658b | 304 | |
el15pjt | 5:083d484e95a1 | 305 | void sw1_isr() |
el15pjt | 3:8782b8b8658b | 306 | { |
el15pjt | 7:14cfb0df30e6 | 307 | g_sw1_flag = 1; /** set flag in ISR by button 2 @param g_sw1_flag 0 or 1*/ |
el15pjt | 5:083d484e95a1 | 308 | } |
el15pjt | 3:8782b8b8658b | 309 | |
el15pjt | 5:083d484e95a1 | 310 | void timer_isr_led() |
el15pjt | 2:329597081c06 | 311 | { |
el15pjt | 7:14cfb0df30e6 | 312 | g_timer_flag_led = 1; /** set flag in ISR by timer_isr_led @param g_timer_flag_led 0 or 1 */ |
el15pjt | 3:8782b8b8658b | 313 | } |
el15pjt | 3:8782b8b8658b | 314 | |
el15pjt | 3:8782b8b8658b | 315 | void timer_isr_srf02() |
el15pjt | 3:8782b8b8658b | 316 | { |
el15pjt | 7:14cfb0df30e6 | 317 | g_timer_flag_srf02 = 1; /** set flag in ISR by ticker_srf02 @param g_timer_flag_srf02 0 or 1 */ |
el15pjt | 4:673930f04866 | 318 | } |
el15pjt | 4:673930f04866 | 319 | |
el15pjt | 4:673930f04866 | 320 | void timer_isr_tone() |
el15pjt | 4:673930f04866 | 321 | { |
el15pjt | 7:14cfb0df30e6 | 322 | g_timer_flag_tone = 1; /** set flag in ISR by ticker_tone @param g_timer_flag_tone 0 or 1 */ |
el15pjt | 7:14cfb0df30e6 | 323 | } |
el15pjt | 7:14cfb0df30e6 | 324 | void timer_isr_standby() |
el15pjt | 7:14cfb0df30e6 | 325 | { |
el15pjt | 7:14cfb0df30e6 | 326 | g_timer_flag_standby = 1; /** set flag in ISR by ticker_tone @param g_timer_flag_tone 0 or 1 */ |
el15pjt | 4:673930f04866 | 327 | } |
el15pjt | 4:673930f04866 | 328 | |
el15pjt | 5:083d484e95a1 | 329 | void menu() |
el15pjt | 4:673930f04866 | 330 | { |
el15pjt | 5:083d484e95a1 | 331 | while(1) { |
el15pjt | 6:b464a8a94d91 | 332 | |
el15pjt | 6:b464a8a94d91 | 333 | |
el15pjt | 5:083d484e95a1 | 334 | if (g_sw1_flag) { |
el15pjt | 5:083d484e95a1 | 335 | g_sw1_flag = 0; |
el15pjt | 7:14cfb0df30e6 | 336 | page++; /// Moves page |
el15pjt | 6:b464a8a94d91 | 337 | lcd.clear(); |
el15pjt | 5:083d484e95a1 | 338 | } |
el15pjt | 5:083d484e95a1 | 339 | switch (page) { |
el15pjt | 5:083d484e95a1 | 340 | case 0: |
el15pjt | 5:083d484e95a1 | 341 | if (g_sw2_flag) { |
el15pjt | 5:083d484e95a1 | 342 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 5:083d484e95a1 | 343 | backlight(); |
el15pjt | 6:b464a8a94d91 | 344 | lcd.clear(); |
el15pjt | 6:b464a8a94d91 | 345 | } else { |
el15pjt | 6:b464a8a94d91 | 346 | int lightbar = bright*84; |
el15pjt | 7:14cfb0df30e6 | 347 | sprintf(buffer2,"*****MENU*****"); |
el15pjt | 7:14cfb0df30e6 | 348 | sprintf(buffer1,"BACKLIGHT"); |
el15pjt | 7:14cfb0df30e6 | 349 | sprintf(buffer3,"%.0f%%",bright*100); |
el15pjt | 7:14cfb0df30e6 | 350 | sprintf(buffer4,"Next Adj"); |
el15pjt | 5:083d484e95a1 | 351 | lcd.printString(buffer2,0,0); |
el15pjt | 5:083d484e95a1 | 352 | lcd.printString(buffer1,0,1); |
el15pjt | 5:083d484e95a1 | 353 | lcd.printString(buffer3,0,2); |
el15pjt | 7:14cfb0df30e6 | 354 | lcd.printString(buffer4,0,5); |
el15pjt | 7:14cfb0df30e6 | 355 | lcd.drawRect(0,26,lightbar,7,1); // move bar up!!!!!!!!!!!!!!!! |
el15pjt | 6:b464a8a94d91 | 356 | lcd.refresh(); |
el15pjt | 6:b464a8a94d91 | 357 | |
el15pjt | 5:083d484e95a1 | 358 | } |
el15pjt | 5:083d484e95a1 | 359 | break; |
el15pjt | 5:083d484e95a1 | 360 | |
el15pjt | 5:083d484e95a1 | 361 | case 1: |
el15pjt | 5:083d484e95a1 | 362 | if (g_sw2_flag) { |
el15pjt | 5:083d484e95a1 | 363 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 5:083d484e95a1 | 364 | if (offset == 20) { |
el15pjt | 5:083d484e95a1 | 365 | offset = 0; |
el15pjt | 5:083d484e95a1 | 366 | } else { |
el15pjt | 5:083d484e95a1 | 367 | offset += 1; |
el15pjt | 5:083d484e95a1 | 368 | } |
el15pjt | 6:b464a8a94d91 | 369 | } else { |
el15pjt | 6:b464a8a94d91 | 370 | length2 = sprintf(buffer2,"*****MENU*****"); |
el15pjt | 6:b464a8a94d91 | 371 | length1 = sprintf(buffer1,"OFFSET"); |
el15pjt | 6:b464a8a94d91 | 372 | length3 = sprintf(buffer3,"%i",offset); |
el15pjt | 7:14cfb0df30e6 | 373 | sprintf(buffer4,"Next Adj"); |
el15pjt | 5:083d484e95a1 | 374 | lcd.printString(buffer2,0,0); |
el15pjt | 5:083d484e95a1 | 375 | lcd.printString(buffer1,0,1); |
el15pjt | 5:083d484e95a1 | 376 | lcd.printString(buffer3,0,2); |
el15pjt | 7:14cfb0df30e6 | 377 | lcd.printString(buffer4,0,5); |
el15pjt | 6:b464a8a94d91 | 378 | lcd.refresh(); |
el15pjt | 5:083d484e95a1 | 379 | } |
el15pjt | 6:b464a8a94d91 | 380 | |
el15pjt | 5:083d484e95a1 | 381 | break; |
el15pjt | 5:083d484e95a1 | 382 | |
el15pjt | 5:083d484e95a1 | 383 | case 2: |
el15pjt | 5:083d484e95a1 | 384 | if (g_sw2_flag) { |
el15pjt | 5:083d484e95a1 | 385 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 5:083d484e95a1 | 386 | if (units == METRIC) { |
el15pjt | 5:083d484e95a1 | 387 | units = IMPERIAL; |
el15pjt | 7:14cfb0df30e6 | 388 | c= 0.3937; |
el15pjt | 5:083d484e95a1 | 389 | } else { |
el15pjt | 5:083d484e95a1 | 390 | units = METRIC; |
el15pjt | 7:14cfb0df30e6 | 391 | c = 1; |
el15pjt | 5:083d484e95a1 | 392 | } |
el15pjt | 5:083d484e95a1 | 393 | } |
el15pjt | 5:083d484e95a1 | 394 | if (units == METRIC) { |
el15pjt | 7:14cfb0df30e6 | 395 | sprintf(buffer3,"METRIC"); |
el15pjt | 7:14cfb0df30e6 | 396 | lcd.printString(buffer3,0,2); |
el15pjt | 5:083d484e95a1 | 397 | } else { |
el15pjt | 7:14cfb0df30e6 | 398 | sprintf(buffer3,"IMPERIAL"); |
el15pjt | 7:14cfb0df30e6 | 399 | lcd.printString(buffer3,0,2); |
el15pjt | 5:083d484e95a1 | 400 | } |
el15pjt | 7:14cfb0df30e6 | 401 | sprintf(buffer2,"*****MENU*****"); |
el15pjt | 7:14cfb0df30e6 | 402 | sprintf(buffer1,"UNITS"); |
el15pjt | 7:14cfb0df30e6 | 403 | sprintf(buffer4,"Next Adj"); |
el15pjt | 6:b464a8a94d91 | 404 | lcd.printString(buffer2,0,0); |
el15pjt | 6:b464a8a94d91 | 405 | lcd.printString(buffer1,0,1); |
el15pjt | 7:14cfb0df30e6 | 406 | lcd.printString(buffer4,0,5); |
el15pjt | 7:14cfb0df30e6 | 407 | lcd.refresh(); |
el15pjt | 6:b464a8a94d91 | 408 | |
el15pjt | 5:083d484e95a1 | 409 | break; |
el15pjt | 5:083d484e95a1 | 410 | |
el15pjt | 5:083d484e95a1 | 411 | case 3: |
el15pjt | 5:083d484e95a1 | 412 | |
el15pjt | 5:083d484e95a1 | 413 | if (g_sw2_flag) { |
el15pjt | 5:083d484e95a1 | 414 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 5:083d484e95a1 | 415 | submenu(); |
el15pjt | 5:083d484e95a1 | 416 | } |
el15pjt | 5:083d484e95a1 | 417 | length2 = sprintf(buffer3,"*****MENU*****"); |
el15pjt | 5:083d484e95a1 | 418 | length3 = sprintf(buffer1,"RANGE"); |
el15pjt | 5:083d484e95a1 | 419 | length3 = sprintf(buffer2,"PARAMETERS"); |
el15pjt | 7:14cfb0df30e6 | 420 | sprintf(buffer4,"Next Adj"); |
el15pjt | 5:083d484e95a1 | 421 | lcd.printString(buffer3,0,0); |
el15pjt | 5:083d484e95a1 | 422 | lcd.printString(buffer1,0,1); |
el15pjt | 5:083d484e95a1 | 423 | lcd.printString(buffer2,0,2); |
el15pjt | 7:14cfb0df30e6 | 424 | lcd.printString(buffer4,0,5); |
el15pjt | 6:b464a8a94d91 | 425 | |
el15pjt | 5:083d484e95a1 | 426 | break; |
el15pjt | 5:083d484e95a1 | 427 | |
el15pjt | 5:083d484e95a1 | 428 | default: |
el15pjt | 5:083d484e95a1 | 429 | lcd.clear(); |
el15pjt | 7:14cfb0df30e6 | 430 | /* //save(); |
el15pjt | 7:14cfb0df30e6 | 431 | |
el15pjt | 7:14cfb0df30e6 | 432 | ///////////////////// Writing list to file example ////////////////////// |
el15pjt | 7:14cfb0df30e6 | 433 | |
el15pjt | 7:14cfb0df30e6 | 434 | // for this example, I'll create some numbers to write to file in a big list |
el15pjt | 7:14cfb0df30e6 | 435 | // a data logger for example will usually append to a file - at a reading |
el15pjt | 7:14cfb0df30e6 | 436 | // at the end rather than creating a new file |
el15pjt | 7:14cfb0df30e6 | 437 | fp = fopen("/sd/settinngs.txt", "a"); |
el15pjt | 7:14cfb0df30e6 | 438 | |
el15pjt | 7:14cfb0df30e6 | 439 | if (fp == NULL) { // if it can't open the file then print error message |
el15pjt | 7:14cfb0df30e6 | 440 | serial.printf("Error! Unable to open file!\n"); |
el15pjt | 7:14cfb0df30e6 | 441 | } else { // opened file so can write |
el15pjt | 7:14cfb0df30e6 | 442 | serial.printf("Writing to file...."); |
el15pjt | 7:14cfb0df30e6 | 443 | for(int i = 1; i <= 50; i++) { |
el15pjt | 7:14cfb0df30e6 | 444 | int r1; |
el15pjt | 7:14cfb0df30e6 | 445 | int r2; |
el15pjt | 7:14cfb0df30e6 | 446 | int r3; |
el15pjt | 7:14cfb0df30e6 | 447 | int r4; |
el15pjt | 7:14cfb0df30e6 | 448 | int r5; |
el15pjt | 7:14cfb0df30e6 | 449 | int r6; |
el15pjt | 7:14cfb0df30e6 | 450 | int r7; |
el15pjt | 7:14cfb0df30e6 | 451 | int offset; // create suitable variables to store the data in the file |
el15pjt | 7:14cfb0df30e6 | 452 | float bright; |
el15pjt | 7:14cfb0df30e6 | 453 | float dummy = 1000.0F/i; // dummy variable |
el15pjt | 7:14cfb0df30e6 | 454 | fprintf(fp, "%d,%f\n",i,dummy); // print formatted string to file (CSV) |
el15pjt | 7:14cfb0df30e6 | 455 | } |
el15pjt | 7:14cfb0df30e6 | 456 | serial.printf("Done.\n"); |
el15pjt | 7:14cfb0df30e6 | 457 | fclose(fp); // ensure you close the file after writing |
el15pjt | 7:14cfb0df30e6 | 458 | } |
el15pjt | 7:14cfb0df30e6 | 459 | |
el15pjt | 7:14cfb0df30e6 | 460 | // you can comment out the writing example to check that the writing has |
el15pjt | 7:14cfb0df30e6 | 461 | // worked - when you run it after commenting, it should still open the |
el15pjt | 7:14cfb0df30e6 | 462 | // file that exists on the SD card - assuming you didn't delete it! |
el15pjt | 7:14cfb0df30e6 | 463 | */ |
el15pjt | 5:083d484e95a1 | 464 | return; |
el15pjt | 5:083d484e95a1 | 465 | } |
el15pjt | 4:673930f04866 | 466 | } |
el15pjt | 7:14cfb0df30e6 | 467 | // lcd.refresh(); |
el15pjt | 7:14cfb0df30e6 | 468 | |
el15pjt | 5:083d484e95a1 | 469 | } |
el15pjt | 5:083d484e95a1 | 470 | void submenu() |
el15pjt | 5:083d484e95a1 | 471 | { |
el15pjt | 7:14cfb0df30e6 | 472 | |
el15pjt | 5:083d484e95a1 | 473 | while(1) { |
el15pjt | 7:14cfb0df30e6 | 474 | /// innterupt used to shift page |
el15pjt | 5:083d484e95a1 | 475 | if (g_sw1_flag) { |
el15pjt | 5:083d484e95a1 | 476 | g_sw1_flag = 0; |
el15pjt | 5:083d484e95a1 | 477 | subpage++; |
el15pjt | 5:083d484e95a1 | 478 | } |
el15pjt | 5:083d484e95a1 | 479 | switch (subpage) { |
el15pjt | 7:14cfb0df30e6 | 480 | ///interupt used to adjust range |
el15pjt | 5:083d484e95a1 | 481 | case 0: |
el15pjt | 5:083d484e95a1 | 482 | if (g_sw2_flag) { |
el15pjt | 5:083d484e95a1 | 483 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 5:083d484e95a1 | 484 | if (r2 == r3) { |
el15pjt | 5:083d484e95a1 | 485 | r2 = 1; |
el15pjt | 5:083d484e95a1 | 486 | } else { |
el15pjt | 5:083d484e95a1 | 487 | r2 = r2+1; |
el15pjt | 5:083d484e95a1 | 488 | } |
el15pjt | 5:083d484e95a1 | 489 | } |
el15pjt | 5:083d484e95a1 | 490 | length2 = sprintf(buffer1,"*****MENU*****"); |
el15pjt | 5:083d484e95a1 | 491 | length3 = sprintf(buffer2,"RANGE"); |
el15pjt | 5:083d484e95a1 | 492 | length3 = sprintf(buffer3,"PARAMETERS"); |
el15pjt | 5:083d484e95a1 | 493 | length4 = sprintf(buffer4,"1Cm to %iCm",r2); |
el15pjt | 7:14cfb0df30e6 | 494 | sprintf(buffer,"Next Adj"); |
el15pjt | 5:083d484e95a1 | 495 | lcd.printString(buffer1,0,0); |
el15pjt | 5:083d484e95a1 | 496 | lcd.printString(buffer2,0,1); |
el15pjt | 5:083d484e95a1 | 497 | lcd.printString(buffer3,0,2); |
el15pjt | 5:083d484e95a1 | 498 | lcd.printString(buffer4,0,3); |
el15pjt | 7:14cfb0df30e6 | 499 | lcd.printString(buffer,0,5); |
el15pjt | 5:083d484e95a1 | 500 | break; |
el15pjt | 5:083d484e95a1 | 501 | |
el15pjt | 5:083d484e95a1 | 502 | case 1: |
el15pjt | 5:083d484e95a1 | 503 | |
el15pjt | 5:083d484e95a1 | 504 | if (g_sw2_flag) { |
el15pjt | 5:083d484e95a1 | 505 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 5:083d484e95a1 | 506 | if (r3 == r4) { |
el15pjt | 5:083d484e95a1 | 507 | r3 = r2; |
el15pjt | 5:083d484e95a1 | 508 | } else { |
el15pjt | 5:083d484e95a1 | 509 | r3 += 1; |
el15pjt | 5:083d484e95a1 | 510 | } |
el15pjt | 5:083d484e95a1 | 511 | } |
el15pjt | 5:083d484e95a1 | 512 | |
el15pjt | 7:14cfb0df30e6 | 513 | sprintf(buffer1,"*****MENU*****"); |
el15pjt | 7:14cfb0df30e6 | 514 | sprintf(buffer2,"RANGE"); |
el15pjt | 7:14cfb0df30e6 | 515 | sprintf(buffer3,"PARAMETERS"); |
el15pjt | 7:14cfb0df30e6 | 516 | sprintf(buffer4,"%iCm to %iCm",r2,r3); |
el15pjt | 7:14cfb0df30e6 | 517 | sprintf(buffer,"Next Adj"); |
el15pjt | 5:083d484e95a1 | 518 | lcd.printString(buffer1,0,0); |
el15pjt | 5:083d484e95a1 | 519 | lcd.printString(buffer2,0,1); |
el15pjt | 5:083d484e95a1 | 520 | lcd.printString(buffer3,0,2); |
el15pjt | 5:083d484e95a1 | 521 | lcd.printString(buffer4,0,3); |
el15pjt | 7:14cfb0df30e6 | 522 | lcd.printString(buffer,0,5); |
el15pjt | 5:083d484e95a1 | 523 | break; |
el15pjt | 5:083d484e95a1 | 524 | |
el15pjt | 5:083d484e95a1 | 525 | case 2: |
el15pjt | 5:083d484e95a1 | 526 | |
el15pjt | 5:083d484e95a1 | 527 | if (g_sw2_flag) { |
el15pjt | 5:083d484e95a1 | 528 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 5:083d484e95a1 | 529 | if (r4 == r5) { |
el15pjt | 5:083d484e95a1 | 530 | r4 = r3; |
el15pjt | 5:083d484e95a1 | 531 | } else { |
el15pjt | 5:083d484e95a1 | 532 | r4 += 1; |
el15pjt | 5:083d484e95a1 | 533 | } |
el15pjt | 5:083d484e95a1 | 534 | } |
el15pjt | 5:083d484e95a1 | 535 | |
el15pjt | 7:14cfb0df30e6 | 536 | sprintf(buffer1,"*****MENU*****"); |
el15pjt | 7:14cfb0df30e6 | 537 | sprintf(buffer2,"RANGE"); |
el15pjt | 7:14cfb0df30e6 | 538 | sprintf(buffer3,"PARAMETERS"); |
el15pjt | 7:14cfb0df30e6 | 539 | sprintf(buffer4,"%iCm to %iCm",r3,r4); |
el15pjt | 7:14cfb0df30e6 | 540 | sprintf(buffer,"Next Adj"); |
el15pjt | 5:083d484e95a1 | 541 | lcd.printString(buffer1,0,0); |
el15pjt | 5:083d484e95a1 | 542 | lcd.printString(buffer2,0,1); |
el15pjt | 5:083d484e95a1 | 543 | lcd.printString(buffer3,0,2); |
el15pjt | 5:083d484e95a1 | 544 | lcd.printString(buffer4,0,3); |
el15pjt | 7:14cfb0df30e6 | 545 | lcd.printString(buffer,0,5); |
el15pjt | 5:083d484e95a1 | 546 | break; |
el15pjt | 5:083d484e95a1 | 547 | |
el15pjt | 5:083d484e95a1 | 548 | case 3: |
el15pjt | 5:083d484e95a1 | 549 | |
el15pjt | 5:083d484e95a1 | 550 | if (g_sw2_flag) { |
el15pjt | 5:083d484e95a1 | 551 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 5:083d484e95a1 | 552 | if (r5 == r6) { |
el15pjt | 5:083d484e95a1 | 553 | r5 = r4; |
el15pjt | 5:083d484e95a1 | 554 | } else { |
el15pjt | 5:083d484e95a1 | 555 | r5 += 1; |
el15pjt | 5:083d484e95a1 | 556 | } |
el15pjt | 5:083d484e95a1 | 557 | } |
el15pjt | 5:083d484e95a1 | 558 | |
el15pjt | 7:14cfb0df30e6 | 559 | sprintf(buffer1,"*****MENU*****"); |
el15pjt | 7:14cfb0df30e6 | 560 | sprintf(buffer2,"RANGE"); |
el15pjt | 7:14cfb0df30e6 | 561 | sprintf(buffer3,"PARAMETERS"); |
el15pjt | 7:14cfb0df30e6 | 562 | sprintf(buffer4,"%iCm to %iCm",r4,r5); |
el15pjt | 7:14cfb0df30e6 | 563 | sprintf(buffer,"Next Adj"); |
el15pjt | 5:083d484e95a1 | 564 | lcd.printString(buffer1,0,0); |
el15pjt | 5:083d484e95a1 | 565 | lcd.printString(buffer2,0,1); |
el15pjt | 5:083d484e95a1 | 566 | lcd.printString(buffer3,0,2); |
el15pjt | 5:083d484e95a1 | 567 | lcd.printString(buffer4,0,3); |
el15pjt | 7:14cfb0df30e6 | 568 | lcd.printString(buffer,0,5); |
el15pjt | 5:083d484e95a1 | 569 | break; |
el15pjt | 5:083d484e95a1 | 570 | case 4: |
el15pjt | 5:083d484e95a1 | 571 | |
el15pjt | 5:083d484e95a1 | 572 | if (g_sw2_flag) { |
el15pjt | 5:083d484e95a1 | 573 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 5:083d484e95a1 | 574 | if (r6 == r7) { |
el15pjt | 5:083d484e95a1 | 575 | r6 = r5; |
el15pjt | 5:083d484e95a1 | 576 | } else { |
el15pjt | 5:083d484e95a1 | 577 | r6 += 1; |
el15pjt | 5:083d484e95a1 | 578 | } |
el15pjt | 5:083d484e95a1 | 579 | } |
el15pjt | 5:083d484e95a1 | 580 | |
el15pjt | 5:083d484e95a1 | 581 | length2 = sprintf(buffer1,"*****MENU*****"); |
el15pjt | 5:083d484e95a1 | 582 | length3 = sprintf(buffer2,"RANGE"); |
el15pjt | 5:083d484e95a1 | 583 | length3 = sprintf(buffer3,"PARAMETERS"); |
el15pjt | 6:b464a8a94d91 | 584 | length3 = sprintf(buffer4,"%iCm to %iCm",r5,r6); |
el15pjt | 7:14cfb0df30e6 | 585 | sprintf(buffer,"Next Adj"); |
el15pjt | 5:083d484e95a1 | 586 | lcd.printString(buffer1,0,0); |
el15pjt | 5:083d484e95a1 | 587 | lcd.printString(buffer2,0,1); |
el15pjt | 5:083d484e95a1 | 588 | lcd.printString(buffer3,0,2); |
el15pjt | 5:083d484e95a1 | 589 | lcd.printString(buffer4,0,3); |
el15pjt | 7:14cfb0df30e6 | 590 | lcd.printString(buffer,0,5); |
el15pjt | 5:083d484e95a1 | 591 | break; |
el15pjt | 5:083d484e95a1 | 592 | case 5: |
el15pjt | 5:083d484e95a1 | 593 | |
el15pjt | 5:083d484e95a1 | 594 | if (g_sw2_flag) { |
el15pjt | 5:083d484e95a1 | 595 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 5:083d484e95a1 | 596 | if (r7 == 300) { |
el15pjt | 5:083d484e95a1 | 597 | r7 = r6; |
el15pjt | 5:083d484e95a1 | 598 | } else { |
el15pjt | 5:083d484e95a1 | 599 | r7 += 1; |
el15pjt | 5:083d484e95a1 | 600 | } |
el15pjt | 5:083d484e95a1 | 601 | } |
el15pjt | 5:083d484e95a1 | 602 | |
el15pjt | 5:083d484e95a1 | 603 | length2 = sprintf(buffer1,"*****MENU*****"); |
el15pjt | 5:083d484e95a1 | 604 | length3 = sprintf(buffer2,"RANGE"); |
el15pjt | 5:083d484e95a1 | 605 | length3 = sprintf(buffer3,"PARAMETERS"); |
el15pjt | 7:14cfb0df30e6 | 606 | sprintf(buffer,"Next Adj"); |
el15pjt | 6:b464a8a94d91 | 607 | length3 = sprintf(buffer4,"%iCm to %iCm",r6,r7); |
el15pjt | 5:083d484e95a1 | 608 | lcd.printString(buffer1,0,0); |
el15pjt | 5:083d484e95a1 | 609 | lcd.printString(buffer2,0,1); |
el15pjt | 5:083d484e95a1 | 610 | lcd.printString(buffer3,0,2); |
el15pjt | 5:083d484e95a1 | 611 | lcd.printString(buffer4,0,3); |
el15pjt | 7:14cfb0df30e6 | 612 | lcd.printString(buffer,0,5); |
el15pjt | 5:083d484e95a1 | 613 | break; |
el15pjt | 5:083d484e95a1 | 614 | |
el15pjt | 5:083d484e95a1 | 615 | default: |
el15pjt | 5:083d484e95a1 | 616 | lcd.clear(); |
el15pjt | 7:14cfb0df30e6 | 617 | // save(); |
el15pjt | 5:083d484e95a1 | 618 | return; |
el15pjt | 5:083d484e95a1 | 619 | } |
el15pjt | 5:083d484e95a1 | 620 | } |
el15pjt | 7:14cfb0df30e6 | 621 | } |
el15pjt | 7:14cfb0df30e6 | 622 | void setup() |
el15pjt | 7:14cfb0df30e6 | 623 | { |
el15pjt | 7:14cfb0df30e6 | 624 | ticker.attach(&timer_isr_led,0.35); /// Attach the ticker for the flashig LEDs |
el15pjt | 7:14cfb0df30e6 | 625 | ticker_srf02.attach(&timer_isr_srf02,0.1); /// Attach the ticker for collecting a range reading |
el15pjt | 7:14cfb0df30e6 | 626 | ticker_tone.attach(&timer_isr_tone,1); /// Attach the ticker which controls the off time of the buzzer 0.1 = 10 beats per second |
el15pjt | 7:14cfb0df30e6 | 627 | ticker_standby.attach(&timer_isr_standby,3.0); |
el15pjt | 7:14cfb0df30e6 | 628 | sw1.rise(&sw1_isr); /// sw1_isr called when button presed on the rising edge |
el15pjt | 7:14cfb0df30e6 | 629 | sw2.rise(&sw2_isr); /// sw2_isr called when button presed on the rising edge |
el15pjt | 7:14cfb0df30e6 | 630 | |
el15pjt | 7:14cfb0df30e6 | 631 | /**Set up LEDs switches and LEDS |
el15pjt | 7:14cfb0df30e6 | 632 | @param r_led 1 or 0 |
el15pjt | 7:14cfb0df30e6 | 633 | @param g_led 1 or 0 |
el15pjt | 7:14cfb0df30e6 | 634 | @param b_led 1 or 0 |
el15pjt | 7:14cfb0df30e6 | 635 | */ |
el15pjt | 7:14cfb0df30e6 | 636 | rr_led = 0; |
el15pjt | 7:14cfb0df30e6 | 637 | a_led = 0; |
el15pjt | 7:14cfb0df30e6 | 638 | gg_led = 0; |
el15pjt | 7:14cfb0df30e6 | 639 | sw2.mode(PullDown); |
el15pjt | 7:14cfb0df30e6 | 640 | sw1.mode(PullDown); |
el15pjt | 5:083d484e95a1 | 641 | } |