Intermittent Program 4180
Dependencies: 4DGL-uLCD-SE mbed
main.cpp@0:a693014b42b1, 2015-05-01 (annotated)
- Committer:
- blasater3
- Date:
- Fri May 01 04:40:52 2015 +0000
- Revision:
- 0:a693014b42b1
For Austin
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
blasater3 | 0:a693014b42b1 | 1 | #include "mbed.h" |
blasater3 | 0:a693014b42b1 | 2 | #include "uLCD_4DGL.h" |
blasater3 | 0:a693014b42b1 | 3 | |
blasater3 | 0:a693014b42b1 | 4 | |
blasater3 | 0:a693014b42b1 | 5 | uLCD_4DGL lcd(p28, p27, p29); |
blasater3 | 0:a693014b42b1 | 6 | DigitalIn pb(p7); |
blasater3 | 0:a693014b42b1 | 7 | DigitalIn pb1(p10); |
blasater3 | 0:a693014b42b1 | 8 | DigitalIn pb2(p13); |
blasater3 | 0:a693014b42b1 | 9 | DigitalIn pb3(p16); |
blasater3 | 0:a693014b42b1 | 10 | |
blasater3 | 0:a693014b42b1 | 11 | int main() { |
blasater3 | 0:a693014b42b1 | 12 | lcd.baudrate(3000000); |
blasater3 | 0:a693014b42b1 | 13 | lcd.background_color(0); |
blasater3 | 0:a693014b42b1 | 14 | lcd.cls(); |
blasater3 | 0:a693014b42b1 | 15 | |
blasater3 | 0:a693014b42b1 | 16 | pb.mode(PullUp); //Intitial Pusbutton Setup |
blasater3 | 0:a693014b42b1 | 17 | pb1.mode(PullUp); |
blasater3 | 0:a693014b42b1 | 18 | pb2.mode(PullUp); |
blasater3 | 0:a693014b42b1 | 19 | pb3.mode(PullUp); |
blasater3 | 0:a693014b42b1 | 20 | wait(.001); |
blasater3 | 0:a693014b42b1 | 21 | |
blasater3 | 0:a693014b42b1 | 22 | lcd.locate(1,2); //Initial Menu Setup |
blasater3 | 0:a693014b42b1 | 23 | lcd.printf("Add Stop<"); |
blasater3 | 0:a693014b42b1 | 24 | lcd.locate(1,4); |
blasater3 | 0:a693014b42b1 | 25 | lcd.printf("Remove Stop "); |
blasater3 | 0:a693014b42b1 | 26 | lcd.locate(1,6); |
blasater3 | 0:a693014b42b1 | 27 | lcd.printf("Exit "); |
blasater3 | 0:a693014b42b1 | 28 | |
blasater3 | 0:a693014b42b1 | 29 | bool count = false; |
blasater3 | 0:a693014b42b1 | 30 | int old_pb=1; |
blasater3 | 0:a693014b42b1 | 31 | int new_pb; |
blasater3 | 0:a693014b42b1 | 32 | |
blasater3 | 0:a693014b42b1 | 33 | int count1=0; |
blasater3 | 0:a693014b42b1 | 34 | int old_pb1=1; |
blasater3 | 0:a693014b42b1 | 35 | int new_pb1; |
blasater3 | 0:a693014b42b1 | 36 | |
blasater3 | 0:a693014b42b1 | 37 | int old_pb2=1; |
blasater3 | 0:a693014b42b1 | 38 | int new_pb2; |
blasater3 | 0:a693014b42b1 | 39 | |
blasater3 | 0:a693014b42b1 | 40 | bool count3 = false; //whether enter has been pressed |
blasater3 | 0:a693014b42b1 | 41 | bool count4 = true; //whether it is currently on add stops or remove stops |
blasater3 | 0:a693014b42b1 | 42 | int old_pb3=1; |
blasater3 | 0:a693014b42b1 | 43 | int new_pb3; |
blasater3 | 0:a693014b42b1 | 44 | bool Menu = true; |
blasater3 | 0:a693014b42b1 | 45 | //Set up the booleans determining what stops are currently being serviced |
blasater3 | 0:a693014b42b1 | 46 | bool stop1 = true; |
blasater3 | 0:a693014b42b1 | 47 | bool stop2 = true; |
blasater3 | 0:a693014b42b1 | 48 | bool stop3 = true; |
blasater3 | 0:a693014b42b1 | 49 | bool stop4 = true; |
blasater3 | 0:a693014b42b1 | 50 | bool running = true; |
blasater3 | 0:a693014b42b1 | 51 | int stop = 1; |
blasater3 | 0:a693014b42b1 | 52 | |
blasater3 | 0:a693014b42b1 | 53 | while(1) { |
blasater3 | 0:a693014b42b1 | 54 | new_pb = pb; |
blasater3 | 0:a693014b42b1 | 55 | new_pb1 = pb1; |
blasater3 | 0:a693014b42b1 | 56 | new_pb2 = pb2; |
blasater3 | 0:a693014b42b1 | 57 | new_pb3 = pb3; |
blasater3 | 0:a693014b42b1 | 58 | |
blasater3 | 0:a693014b42b1 | 59 | if(!Menu) { |
blasater3 | 0:a693014b42b1 | 60 | if(running && stop == 1){ |
blasater3 | 0:a693014b42b1 | 61 | lcd.locate(1,5); |
blasater3 | 0:a693014b42b1 | 62 | lcd.printf("Moving to Stop1 "); |
blasater3 | 0:a693014b42b1 | 63 | } |
blasater3 | 0:a693014b42b1 | 64 | if(!running && stop == 1){ |
blasater3 | 0:a693014b42b1 | 65 | lcd.locate(1,5); |
blasater3 | 0:a693014b42b1 | 66 | lcd.printf("Waiting at Stop1"); |
blasater3 | 0:a693014b42b1 | 67 | } |
blasater3 | 0:a693014b42b1 | 68 | if(running && stop == 2){ |
blasater3 | 0:a693014b42b1 | 69 | lcd.locate(1,5); |
blasater3 | 0:a693014b42b1 | 70 | lcd.printf("Moving to Stop2 "); |
blasater3 | 0:a693014b42b1 | 71 | } |
blasater3 | 0:a693014b42b1 | 72 | if(!running && stop == 2){ |
blasater3 | 0:a693014b42b1 | 73 | lcd.locate(1,5); |
blasater3 | 0:a693014b42b1 | 74 | lcd.printf("Waiting at Stop2"); |
blasater3 | 0:a693014b42b1 | 75 | } |
blasater3 | 0:a693014b42b1 | 76 | if(running && stop == 3{ |
blasater3 | 0:a693014b42b1 | 77 | lcd.locate(1,5); |
blasater3 | 0:a693014b42b1 | 78 | lcd.printf("Moving to Stop3"); |
blasater3 | 0:a693014b42b1 | 79 | } |
blasater3 | 0:a693014b42b1 | 80 | if(!running && stop == 3{ |
blasater3 | 0:a693014b42b1 | 81 | lcd.locate(1,5); |
blasater3 | 0:a693014b42b1 | 82 | lcd.printf("Waiting at Stop3); |
blasater3 | 0:a693014b42b1 | 83 | } |
blasater3 | 0:a693014b42b1 | 84 | if(running && stop == 4{ |
blasater3 | 0:a693014b42b1 | 85 | lcd.locate(1,5); |
blasater3 | 0:a693014b42b1 | 86 | lcd.printf("Moving to Stop4 "); |
blasater3 | 0:a693014b42b1 | 87 | } |
blasater3 | 0:a693014b42b1 | 88 | if(!running && stop == 4){ |
blasater3 | 0:a693014b42b1 | 89 | lcd.locate(1,5); |
blasater3 | 0:a693014b42b1 | 90 | lcd.printf("Waiting at Stop4"); |
blasater3 | 0:a693014b42b1 | 91 | } |
blasater3 | 0:a693014b42b1 | 92 | } |
blasater3 | 0:a693014b42b1 | 93 | |
blasater3 | 0:a693014b42b1 | 94 | if(Menu) { //All of the below runs the menu interactions |
blasater3 | 0:a693014b42b1 | 95 | if ((new_pb==0) && (old_pb==1)) count = !count; |
blasater3 | 0:a693014b42b1 | 96 | if ((new_pb1==0) && (old_pb1==1) && count1 < 3) count1++; |
blasater3 | 0:a693014b42b1 | 97 | if ((new_pb2==0) && (old_pb2==1) && count1 > 0) count1--; |
blasater3 | 0:a693014b42b1 | 98 | if ((new_pb3==0) && (old_pb3==1)) { |
blasater3 | 0:a693014b42b1 | 99 | count3 = !count3; |
blasater3 | 0:a693014b42b1 | 100 | lcd.cls(); |
blasater3 | 0:a693014b42b1 | 101 | count1 = 0; |
blasater3 | 0:a693014b42b1 | 102 | } |
blasater3 | 0:a693014b42b1 | 103 | |
blasater3 | 0:a693014b42b1 | 104 | if(count && !count3){ |
blasater3 | 0:a693014b42b1 | 105 | lcd.cls(); |
blasater3 | 0:a693014b42b1 | 106 | count1 = 0; |
blasater3 | 0:a693014b42b1 | 107 | count = false; |
blasater3 | 0:a693014b42b1 | 108 | } |
blasater3 | 0:a693014b42b1 | 109 | |
blasater3 | 0:a693014b42b1 | 110 | if(count && count3 && count4){ |
blasater3 | 0:a693014b42b1 | 111 | if(count1 == 0) stop1 = true; |
blasater3 | 0:a693014b42b1 | 112 | if(count1 == 1) stop2 = true; |
blasater3 | 0:a693014b42b1 | 113 | if(count1 == 2) stop3 = true; |
blasater3 | 0:a693014b42b1 | 114 | if(count3 == 3) stop4 = true; |
blasater3 | 0:a693014b42b1 | 115 | count = false; |
blasater3 | 0:a693014b42b1 | 116 | } |
blasater3 | 0:a693014b42b1 | 117 | |
blasater3 | 0:a693014b42b1 | 118 | if(count && count3 && count4){ |
blasater3 | 0:a693014b42b1 | 119 | if(count1 == 0) stop1 = false; |
blasater3 | 0:a693014b42b1 | 120 | if(count1 == 1) stop2 = false; |
blasater3 | 0:a693014b42b1 | 121 | if(count1 == 2) stop3 = false; |
blasater3 | 0:a693014b42b1 | 122 | if(count3 == 3) stop4 = false; |
blasater3 | 0:a693014b42b1 | 123 | count = false; |
blasater3 | 0:a693014b42b1 | 124 | } |
blasater3 | 0:a693014b42b1 | 125 | |
blasater3 | 0:a693014b42b1 | 126 | if(!count) { |
blasater3 | 0:a693014b42b1 | 127 | if(!count3) { |
blasater3 | 0:a693014b42b1 | 128 | lcd.locate(1,1); |
blasater3 | 0:a693014b42b1 | 129 | lcd.printf(" "); |
blasater3 | 0:a693014b42b1 | 130 | } |
blasater3 | 0:a693014b42b1 | 131 | |
blasater3 | 0:a693014b42b1 | 132 | if(count3 && count4 && count1==0) { |
blasater3 | 0:a693014b42b1 | 133 | lcd.locate(1,1); |
blasater3 | 0:a693014b42b1 | 134 | lcd.printf("Add stops"); |
blasater3 | 0:a693014b42b1 | 135 | lcd.locate(1,2); //Initial Menu Setup for adding stops |
blasater3 | 0:a693014b42b1 | 136 | lcd.printf("Stop 1< "); |
blasater3 | 0:a693014b42b1 | 137 | lcd.locate(1,4); |
blasater3 | 0:a693014b42b1 | 138 | lcd.printf("Stop 2 "); |
blasater3 | 0:a693014b42b1 | 139 | lcd.locate(1,6); |
blasater3 | 0:a693014b42b1 | 140 | lcd.printf("Stop 3 "); |
blasater3 | 0:a693014b42b1 | 141 | lcd.locate(1,8); |
blasater3 | 0:a693014b42b1 | 142 | lcd.printf("Stop 4 "); |
blasater3 | 0:a693014b42b1 | 143 | } |
blasater3 | 0:a693014b42b1 | 144 | if(count3 && count4 && count1==1) { |
blasater3 | 0:a693014b42b1 | 145 | lcd.locate(1,1); |
blasater3 | 0:a693014b42b1 | 146 | lcd.printf("Add stops"); |
blasater3 | 0:a693014b42b1 | 147 | lcd.locate(1,2); //Initial Menu Setup for adding stops |
blasater3 | 0:a693014b42b1 | 148 | lcd.printf("Stop 1 "); |
blasater3 | 0:a693014b42b1 | 149 | lcd.locate(1,4); |
blasater3 | 0:a693014b42b1 | 150 | lcd.printf("Stop 2< "); |
blasater3 | 0:a693014b42b1 | 151 | lcd.locate(1,6); |
blasater3 | 0:a693014b42b1 | 152 | lcd.printf("Stop 3 "); |
blasater3 | 0:a693014b42b1 | 153 | lcd.locate(1,8); |
blasater3 | 0:a693014b42b1 | 154 | lcd.printf("Stop 4 "); |
blasater3 | 0:a693014b42b1 | 155 | } |
blasater3 | 0:a693014b42b1 | 156 | if(count3 && count4 && count1==2) { |
blasater3 | 0:a693014b42b1 | 157 | lcd.locate(1,1); |
blasater3 | 0:a693014b42b1 | 158 | lcd.printf("Add stops"); |
blasater3 | 0:a693014b42b1 | 159 | lcd.locate(1,2); //Initial Menu Setup for adding stops |
blasater3 | 0:a693014b42b1 | 160 | lcd.printf("Stop 1 "); |
blasater3 | 0:a693014b42b1 | 161 | lcd.locate(1,4); |
blasater3 | 0:a693014b42b1 | 162 | lcd.printf("Stop 2 "); |
blasater3 | 0:a693014b42b1 | 163 | lcd.locate(1,6); |
blasater3 | 0:a693014b42b1 | 164 | lcd.printf("Stop 3<"); |
blasater3 | 0:a693014b42b1 | 165 | lcd.locate(1,8); |
blasater3 | 0:a693014b42b1 | 166 | lcd.printf("Stop 4 "); |
blasater3 | 0:a693014b42b1 | 167 | } |
blasater3 | 0:a693014b42b1 | 168 | if(count3 && count4 && count1==3) { |
blasater3 | 0:a693014b42b1 | 169 | lcd.locate(1,1); |
blasater3 | 0:a693014b42b1 | 170 | lcd.printf("Add stops"); |
blasater3 | 0:a693014b42b1 | 171 | lcd.locate(1,2); //Initial Menu Setup for adding stops |
blasater3 | 0:a693014b42b1 | 172 | lcd.printf("Stop 1 "); |
blasater3 | 0:a693014b42b1 | 173 | lcd.locate(1,4); |
blasater3 | 0:a693014b42b1 | 174 | lcd.printf("Stop 2 "); |
blasater3 | 0:a693014b42b1 | 175 | lcd.locate(1,6); |
blasater3 | 0:a693014b42b1 | 176 | lcd.printf("Stop 3 "); |
blasater3 | 0:a693014b42b1 | 177 | lcd.locate(1,8); |
blasater3 | 0:a693014b42b1 | 178 | lcd.printf("Stop 4<"); |
blasater3 | 0:a693014b42b1 | 179 | } |
blasater3 | 0:a693014b42b1 | 180 | |
blasater3 | 0:a693014b42b1 | 181 | if(count3 && !count4 && count1 == 0) { |
blasater3 | 0:a693014b42b1 | 182 | lcd.locate(1,1); |
blasater3 | 0:a693014b42b1 | 183 | lcd.printf("Remove Stops"); |
blasater3 | 0:a693014b42b1 | 184 | lcd.locate(1,2); //Initial Menu Setup for removing |
blasater3 | 0:a693014b42b1 | 185 | lcd.printf("Stop 1< "); |
blasater3 | 0:a693014b42b1 | 186 | lcd.locate(1,4); |
blasater3 | 0:a693014b42b1 | 187 | lcd.printf("Stop 2 "); |
blasater3 | 0:a693014b42b1 | 188 | lcd.locate(1,6); |
blasater3 | 0:a693014b42b1 | 189 | lcd.printf("Stop 3 "); |
blasater3 | 0:a693014b42b1 | 190 | lcd.locate(1,8); |
blasater3 | 0:a693014b42b1 | 191 | lcd.printf("Stop 4 "); |
blasater3 | 0:a693014b42b1 | 192 | } |
blasater3 | 0:a693014b42b1 | 193 | if(count3 && !count4 && count1 == 1) { |
blasater3 | 0:a693014b42b1 | 194 | lcd.locate(1,1); |
blasater3 | 0:a693014b42b1 | 195 | lcd.printf("Remove Stops"); |
blasater3 | 0:a693014b42b1 | 196 | lcd.locate(1,2); //Initial Menu Setup for removing |
blasater3 | 0:a693014b42b1 | 197 | lcd.printf("Stop 1 "); |
blasater3 | 0:a693014b42b1 | 198 | lcd.locate(1,4); |
blasater3 | 0:a693014b42b1 | 199 | lcd.printf("Stop 2< "); |
blasater3 | 0:a693014b42b1 | 200 | lcd.locate(1,6); |
blasater3 | 0:a693014b42b1 | 201 | lcd.printf("Stop 3 "); |
blasater3 | 0:a693014b42b1 | 202 | lcd.locate(1,8); |
blasater3 | 0:a693014b42b1 | 203 | lcd.printf("Stop 4 "); |
blasater3 | 0:a693014b42b1 | 204 | } |
blasater3 | 0:a693014b42b1 | 205 | if(count3 && !count4 && count1 == 2) { |
blasater3 | 0:a693014b42b1 | 206 | lcd.locate(1,1); |
blasater3 | 0:a693014b42b1 | 207 | lcd.printf("Remove Stops"); |
blasater3 | 0:a693014b42b1 | 208 | lcd.locate(1,2); //Initial Menu Setup for removing |
blasater3 | 0:a693014b42b1 | 209 | lcd.printf("Stop 1 "); |
blasater3 | 0:a693014b42b1 | 210 | lcd.locate(1,4); |
blasater3 | 0:a693014b42b1 | 211 | lcd.printf("Stop 2 "); |
blasater3 | 0:a693014b42b1 | 212 | lcd.locate(1,6); |
blasater3 | 0:a693014b42b1 | 213 | lcd.printf("Stop 3<"); |
blasater3 | 0:a693014b42b1 | 214 | lcd.locate(1,8); |
blasater3 | 0:a693014b42b1 | 215 | lcd.printf("Stop 4 "); |
blasater3 | 0:a693014b42b1 | 216 | }if(count3 && !count4 && count1 == 3) { |
blasater3 | 0:a693014b42b1 | 217 | lcd.locate(1,1); |
blasater3 | 0:a693014b42b1 | 218 | lcd.printf("Remove Stops"); |
blasater3 | 0:a693014b42b1 | 219 | lcd.locate(1,2); //Initial Menu Setup for removing |
blasater3 | 0:a693014b42b1 | 220 | lcd.printf("Stop 1 "); |
blasater3 | 0:a693014b42b1 | 221 | lcd.locate(1,4); |
blasater3 | 0:a693014b42b1 | 222 | lcd.printf("Stop 2 "); |
blasater3 | 0:a693014b42b1 | 223 | lcd.locate(1,6); |
blasater3 | 0:a693014b42b1 | 224 | lcd.printf("Stop 3 "); |
blasater3 | 0:a693014b42b1 | 225 | lcd.locate(1,8); |
blasater3 | 0:a693014b42b1 | 226 | lcd.printf("Stop 4<"); |
blasater3 | 0:a693014b42b1 | 227 | } |
blasater3 | 0:a693014b42b1 | 228 | if(count1 == 0 && !count3) { |
blasater3 | 0:a693014b42b1 | 229 | lcd.locate(1,2); //Initial Menu Setup |
blasater3 | 0:a693014b42b1 | 230 | lcd.printf("Add Stop<"); |
blasater3 | 0:a693014b42b1 | 231 | count4 = true; |
blasater3 | 0:a693014b42b1 | 232 | } if(count1 != 0 && !count3) { |
blasater3 | 0:a693014b42b1 | 233 | lcd.locate(1,2); //Initial Menu Setup |
blasater3 | 0:a693014b42b1 | 234 | lcd.printf("Add Stop "); |
blasater3 | 0:a693014b42b1 | 235 | } |
blasater3 | 0:a693014b42b1 | 236 | |
blasater3 | 0:a693014b42b1 | 237 | if(count1 == 1 && !count3) { |
blasater3 | 0:a693014b42b1 | 238 | lcd.locate(1,4); |
blasater3 | 0:a693014b42b1 | 239 | lcd.printf("Remove Stop<"); |
blasater3 | 0:a693014b42b1 | 240 | count4 = false; |
blasater3 | 0:a693014b42b1 | 241 | } if(count1 != 1 && !count3) { |
blasater3 | 0:a693014b42b1 | 242 | lcd.locate(1,4); |
blasater3 | 0:a693014b42b1 | 243 | lcd.printf("Remove Stop "); |
blasater3 | 0:a693014b42b1 | 244 | } |
blasater3 | 0:a693014b42b1 | 245 | |
blasater3 | 0:a693014b42b1 | 246 | if(count1 == 2 && !count3) { |
blasater3 | 0:a693014b42b1 | 247 | lcd.locate(1,6); |
blasater3 | 0:a693014b42b1 | 248 | lcd.printf("Exit<"); |
blasater3 | 0:a693014b42b1 | 249 | } if(count1 != 2 && !count3) { |
blasater3 | 0:a693014b42b1 | 250 | lcd.locate(1,6); |
blasater3 | 0:a693014b42b1 | 251 | lcd.printf("Exit "); |
blasater3 | 0:a693014b42b1 | 252 | } |
blasater3 | 0:a693014b42b1 | 253 | } |
blasater3 | 0:a693014b42b1 | 254 | } |
blasater3 | 0:a693014b42b1 | 255 | |
blasater3 | 0:a693014b42b1 | 256 | |
blasater3 | 0:a693014b42b1 | 257 | old_pb = new_pb; |
blasater3 | 0:a693014b42b1 | 258 | old_pb1 = new_pb1; |
blasater3 | 0:a693014b42b1 | 259 | old_pb2 = new_pb2; |
blasater3 | 0:a693014b42b1 | 260 | old_pb3 = new_pb3; |
blasater3 | 0:a693014b42b1 | 261 | } |
blasater3 | 0:a693014b42b1 | 262 | } |