Coursework

Committer:
sesa514652
Date:
Thu Jan 13 20:18:10 2022 +0000
Revision:
15:234321e80678
Parent:
12:ceea378d5691
Child:
16:2646c1c4e62e
Start of menu,

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sesa514652 0:1f799c7cce2b 1 #include "mbed.h"
sesa514652 0:1f799c7cce2b 2 #include "Joystick.h"
sesa514652 0:1f799c7cce2b 3 #include "N5110.h"
sesa514652 0:1f799c7cce2b 4 #include "hcsr04.h"
sesa514652 3:6ecb75a2675c 5 #include "Piezo.h"
sesa514652 8:770d168713cc 6 #include "string"
sesa514652 12:ceea378d5691 7 // FSM Menu
sesa514652 12:ceea378d5691 8 // defines directions as 0/1. Note UPPERCASE
sesa514652 12:ceea378d5691 9 #define UP 0
sesa514652 12:ceea378d5691 10 #define DOWN 1
sesa514652 12:ceea378d5691 11 // set inital state
sesa514652 12:ceea378d5691 12 volatile int state = 0;
sesa514652 12:ceea378d5691 13 // set initial direction
sesa514652 12:ceea378d5691 14 int direction = UP;
sesa514652 12:ceea378d5691 15 // array of states in the FSM, each element is the output of the counter
sesa514652 12:ceea378d5691 16 // set the output in binary to make it easier, 0 is LED on, 1 is LED off
sesa514652 12:ceea378d5691 17 string fsm[4] = {"buttonA_isr","buttonB_isr","buttonAsss_isr","buttonA_isr"};
sesa514652 12:ceea378d5691 18 volatile int Press;
sesa514652 10:42e70b596099 19
sesa514652 5:9b2c976ca318 20 // y x button
sesa514652 0:1f799c7cce2b 21 Joystick joystick(PTB10,PTB11,PTC16);
sesa514652 0:1f799c7cce2b 22 HCSR04 sensor(D14, D15);
sesa514652 3:6ecb75a2675c 23 Piezo Buzzer(PTC10);
sesa514652 8:770d168713cc 24 //Bringing in buttons
sesa514652 8:770d168713cc 25 InterruptIn buttonA(PTB9);
sesa514652 8:770d168713cc 26 InterruptIn buttonB(PTD0);
sesa514652 8:770d168713cc 27 InterruptIn buttonX(PTC17);
sesa514652 8:770d168713cc 28 InterruptIn buttonY(PTC12);
sesa514652 11:1dec05b7d1c1 29 InterruptIn buttonStart(PTC5);
sesa514652 11:1dec05b7d1c1 30 InterruptIn buttonBack(PTB19);
sesa514652 11:1dec05b7d1c1 31 InterruptIn buttonLeft(PTB18);
sesa514652 11:1dec05b7d1c1 32 InterruptIn buttonRight(PTB3);
sesa514652 0:1f799c7cce2b 33
sesa514652 11:1dec05b7d1c1 34 // create an event queue
sesa514652 11:1dec05b7d1c1 35 EventQueue queue; // events are needed to get arround the printf issue
sesa514652 5:9b2c976ca318 36 //rows,cols
sesa514652 0:1f799c7cce2b 37 int sprite[8][5] = {
sesa514652 0:1f799c7cce2b 38 { 0,0,1,0,0 },
sesa514652 0:1f799c7cce2b 39 { 0,1,1,1,0 },
sesa514652 0:1f799c7cce2b 40 { 0,0,1,0,0 },
sesa514652 0:1f799c7cce2b 41 { 0,1,1,1,0 },
sesa514652 0:1f799c7cce2b 42 { 1,1,1,1,1 },
sesa514652 0:1f799c7cce2b 43 { 1,1,1,1,1 },
sesa514652 0:1f799c7cce2b 44 { 1,1,0,1,1 },
sesa514652 0:1f799c7cce2b 45 { 1,1,0,1,1 },
sesa514652 5:9b2c976ca318 46 };
sesa514652 11:1dec05b7d1c1 47 void init_K64F(); // Start K64fBoard
sesa514652 11:1dec05b7d1c1 48
sesa514652 11:1dec05b7d1c1 49 void buttonA_isr(); // Button A interrupt service routine
sesa514652 11:1dec05b7d1c1 50 void buttonB_isr(); // Button B interrupt service routine
sesa514652 11:1dec05b7d1c1 51 void buttonX_isr(); // Button X interrupt service routine
sesa514652 11:1dec05b7d1c1 52 void buttonY_isr(); // Button Y interrupt service routine
sesa514652 11:1dec05b7d1c1 53 void buttonStart_isr(); // Button Start interrupt service routine
sesa514652 11:1dec05b7d1c1 54 void buttonBack_isr(); // Button Back interrupt service routine
sesa514652 11:1dec05b7d1c1 55 void buttonLeft_isr(); // Button Left interrupt service routine
sesa514652 11:1dec05b7d1c1 56 void buttonRight_isr(); // Button Right interrupt service routine
sesa514652 11:1dec05b7d1c1 57 volatile int g_buttonA_flag = 0; // Global Flag
sesa514652 11:1dec05b7d1c1 58 volatile int g_buttonB_flag = 0; // Global Flag
sesa514652 11:1dec05b7d1c1 59 volatile int g_buttonX_flag = 0; // Global Flag
sesa514652 11:1dec05b7d1c1 60 volatile int g_buttonY_flag = 0; // Global Flag
sesa514652 11:1dec05b7d1c1 61 volatile int g_buttonStart_flag = 0; // Global Flag
sesa514652 11:1dec05b7d1c1 62 volatile int g_buttonBack_flag = 0; // Global Flag
sesa514652 11:1dec05b7d1c1 63 volatile int g_buttonLeft_flag = 0; // Global Flag
sesa514652 11:1dec05b7d1c1 64 volatile int g_buttonRight_flag = 0; // Global Flag
sesa514652 15:234321e80678 65 int buttonCounter();
sesa514652 11:1dec05b7d1c1 66 //volatile int g_buttonA_counter = 0; // Global counter
sesa514652 8:770d168713cc 67 //Test function after research C++ lanuage 05/01/22
sesa514652 4:167ce930c9d5 68 int cube(int num){
sesa514652 11:1dec05b7d1c1 69 return num*num;
sesa514652 5:9b2c976ca318 70 };
sesa514652 10:42e70b596099 71 // Menu Items
sesa514652 10:42e70b596099 72 int page1;
sesa514652 10:42e70b596099 73 int page2;
sesa514652 10:42e70b596099 74 int page3;
sesa514652 10:42e70b596099 75 string Listitem1 = "Game"; // guess distance
sesa514652 10:42e70b596099 76 string Listitem2 = "Measure"; // measure distance of object
sesa514652 10:42e70b596099 77 string Listitem3 = "Detect"; // alarm when object is dectected
sesa514652 5:9b2c976ca318 78 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
sesa514652 9:cdd7d9a123f9 79 /* Test of the interup an operating the buzzer this kills the board
sesa514652 9:cdd7d9a123f9 80 void buzzme(){
sesa514652 9:cdd7d9a123f9 81 Buzzer.play(200,120);
sesa514652 9:cdd7d9a123f9 82 wait_ms(5);
sesa514652 9:cdd7d9a123f9 83 Buzzer.play(200,120);;
sesa514652 9:cdd7d9a123f9 84 }
sesa514652 9:cdd7d9a123f9 85 */
sesa514652 11:1dec05b7d1c1 86 void printme(){
sesa514652 9:cdd7d9a123f9 87
sesa514652 11:1dec05b7d1c1 88 volatile double x ;
sesa514652 11:1dec05b7d1c1 89 x = 1;
sesa514652 10:42e70b596099 90 printf("%f\n",x);
sesa514652 11:1dec05b7d1c1 91 // return 0;
sesa514652 9:cdd7d9a123f9 92 }
sesa514652 10:42e70b596099 93
sesa514652 10:42e70b596099 94
sesa514652 10:42e70b596099 95 //void returnme(){
sesa514652 10:42e70b596099 96 //int num;
sesa514652 10:42e70b596099 97 // return num*num;
sesa514652 10:42e70b596099 98 // };
sesa514652 0:1f799c7cce2b 99 int main() {
sesa514652 5:9b2c976ca318 100 //initialise Joystic
sesa514652 5:9b2c976ca318 101 joystick.init();
sesa514652 5:9b2c976ca318 102
sesa514652 11:1dec05b7d1c1 103 // create a thread that'll run the event queue's dispatch function
sesa514652 11:1dec05b7d1c1 104 Thread eventThread;
sesa514652 11:1dec05b7d1c1 105 eventThread.start(callback(&queue, &EventQueue::dispatch_forever));
sesa514652 11:1dec05b7d1c1 106
sesa514652 11:1dec05b7d1c1 107 buttonA.rise(queue.event(&buttonA_isr)); // This is used to call the function putting it in queue allowing the screen toupdat no muxt error
sesa514652 11:1dec05b7d1c1 108 buttonB.rise(queue.event(&buttonB_isr));
sesa514652 11:1dec05b7d1c1 109 buttonX.rise(queue.event(&buttonX_isr));
sesa514652 11:1dec05b7d1c1 110 buttonY.rise(queue.event(&buttonY_isr));
sesa514652 11:1dec05b7d1c1 111 buttonStart.rise(queue.event(&buttonStart_isr)); // This is used to call the function putting it in queue allowing the screen toupdat no muxt error
sesa514652 11:1dec05b7d1c1 112 buttonBack.rise(queue.event(&buttonBack_isr));
sesa514652 11:1dec05b7d1c1 113 buttonLeft.rise(queue.event(&buttonLeft_isr));
sesa514652 11:1dec05b7d1c1 114 buttonRight.rise(queue.event(&buttonRight_isr));
sesa514652 5:9b2c976ca318 115 //first need to initialise display
sesa514652 5:9b2c976ca318 116 lcd.init();
sesa514652 8:770d168713cc 117
sesa514652 12:ceea378d5691 118 // Button A is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister
sesa514652 8:770d168713cc 119 buttonA.mode(PullDown);
sesa514652 10:42e70b596099 120 // Button B is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister
sesa514652 10:42e70b596099 121 buttonB.mode(PullDown);
sesa514652 10:42e70b596099 122 // Button X is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister
sesa514652 10:42e70b596099 123 buttonX.mode(PullDown);
sesa514652 10:42e70b596099 124 // Button Y is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister
sesa514652 10:42e70b596099 125 buttonY.mode(PullDown);
sesa514652 11:1dec05b7d1c1 126 // Button Start is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister
sesa514652 11:1dec05b7d1c1 127 buttonStart.mode(PullDown);
sesa514652 11:1dec05b7d1c1 128 // Button Back is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister
sesa514652 11:1dec05b7d1c1 129 buttonBack.mode(PullDown);
sesa514652 11:1dec05b7d1c1 130 // Button Left is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister
sesa514652 11:1dec05b7d1c1 131 buttonLeft.mode(PullDown);
sesa514652 11:1dec05b7d1c1 132 // Button Right is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister
sesa514652 11:1dec05b7d1c1 133 buttonRight.mode(PullDown);
sesa514652 8:770d168713cc 134
sesa514652 8:770d168713cc 135 // It will return 0 by default and a 1 when pressed i.e. cause a rising edge
sesa514652 11:1dec05b7d1c1 136 // buttonA.rise(&buttonA_isr);
sesa514652 10:42e70b596099 137 // It will return 0 by default and a 1 when pressed i.e. cause a rising edge
sesa514652 11:1dec05b7d1c1 138 // buttonB.rise(&buttonB_isr);
sesa514652 10:42e70b596099 139 // It will return 0 by default and a 1 when pressed i.e. cause a rising edge
sesa514652 11:1dec05b7d1c1 140 //buttonX.rise(&buttonX_isr);
sesa514652 10:42e70b596099 141 // It will return 0 by default and a 1 when pressed i.e. cause a rising edge
sesa514652 11:1dec05b7d1c1 142 // buttonY.rise(&buttonY_isr);
sesa514652 8:770d168713cc 143
sesa514652 8:770d168713cc 144
sesa514652 5:9b2c976ca318 145
sesa514652 5:9b2c976ca318 146 //change set contrast in range 0.0 to 1.0
sesa514652 5:9b2c976ca318 147 //0.5 appears to be a good starting point
sesa514652 5:9b2c976ca318 148 lcd.setContrast(0.5);
sesa514652 5:9b2c976ca318 149
sesa514652 5:9b2c976ca318 150 //Buzzer.period(10.0f);
sesa514652 5:9b2c976ca318 151 //Buzzer.pulsewidth(1);
sesa514652 6:f7f30e0e3bed 152 //Test Struct after research 05/01/22
sesa514652 6:f7f30e0e3bed 153 struct ObjectDefine{
sesa514652 7:ce70a873aa70 154 int qwer;
sesa514652 6:f7f30e0e3bed 155 float Distance;
sesa514652 7:ce70a873aa70 156 char te;
sesa514652 7:ce70a873aa70 157 double dubs;
sesa514652 7:ce70a873aa70 158 string namestruct;
sesa514652 8:770d168713cc 159 // string ;
sesa514652 6:f7f30e0e3bed 160 };
sesa514652 7:ce70a873aa70 161 // Test Class 06/01/22
sesa514652 10:42e70b596099 162 class myClass{
sesa514652 7:ce70a873aa70 163 public:
sesa514652 7:ce70a873aa70 164 string nameclass ;
sesa514652 7:ce70a873aa70 165 double dubss;
sesa514652 7:ce70a873aa70 166 int inty;
sesa514652 7:ce70a873aa70 167 };
sesa514652 7:ce70a873aa70 168 myClass Class1;
sesa514652 7:ce70a873aa70 169 Class1.nameclass ="firstclass";
sesa514652 10:42e70b596099 170 ObjectDefine Object1;
sesa514652 10:42e70b596099 171 Object1.qwer = 12;
sesa514652 6:f7f30e0e3bed 172 Object1.Distance = 34;
sesa514652 7:ce70a873aa70 173 Object1.te = 'A';
sesa514652 7:ce70a873aa70 174 Object1.dubs = 23;
sesa514652 10:42e70b596099 175 Object1.namestruct = "name";
sesa514652 9:cdd7d9a123f9 176 //buttonA.rise(&buzzme); Omitted due to error
sesa514652 10:42e70b596099 177 //buttonA.rise(&printme,10);
sesa514652 10:42e70b596099 178 //buttonA.rise(&returnme);
sesa514652 0:1f799c7cce2b 179 while(1) {
sesa514652 5:9b2c976ca318 180 //Tune(Buzzer,So6,8);
sesa514652 5:9b2c976ca318 181 //Stop_tunes(Buzzer);
sesa514652 8:770d168713cc 182 //Section of code to try to get the button press to be recorded
sesa514652 9:cdd7d9a123f9 183 //bool button = buttonA.read();
sesa514652 10:42e70b596099 184 //printf("%f\n", g_buttonA_flag );
sesa514652 10:42e70b596099 185 //Recording button presses
sesa514652 12:ceea378d5691 186
sesa514652 12:ceea378d5691 187 // swap direction when button has been pressed
sesa514652 12:ceea378d5691 188 // (could just use ! but want this to be explicit to aid understanding)
sesa514652 12:ceea378d5691 189 if (direction == UP) {
sesa514652 12:ceea378d5691 190 direction = DOWN;
sesa514652 12:ceea378d5691 191 }
sesa514652 12:ceea378d5691 192 else {
sesa514652 12:ceea378d5691 193 direction = UP;
sesa514652 12:ceea378d5691 194 string output;
sesa514652 12:ceea378d5691 195 output = fsm[state];
sesa514652 12:ceea378d5691 196
sesa514652 12:ceea378d5691 197
sesa514652 11:1dec05b7d1c1 198 int result;
sesa514652 11:1dec05b7d1c1 199 result = cube(5);
sesa514652 11:1dec05b7d1c1 200 printf("Button A pressed %f\n", cube(5));
sesa514652 11:1dec05b7d1c1 201 int button_counter;
sesa514652 10:42e70b596099 202 if (g_buttonA_flag){
sesa514652 11:1dec05b7d1c1 203 button_counter = button_counter +1;
sesa514652 11:1dec05b7d1c1 204 //case (test)
sesa514652 10:42e70b596099 205 g_buttonA_flag = 0; // if it has, clear the flag
sesa514652 10:42e70b596099 206
sesa514652 10:42e70b596099 207 // send message over serial port - can observe in CoolTerm etc.
sesa514652 11:1dec05b7d1c1 208 printf("Button A pressed %f\n", button_counter);
sesa514652 10:42e70b596099 209 }
sesa514652 10:42e70b596099 210 if (g_buttonB_flag){
sesa514652 10:42e70b596099 211 g_buttonB_flag = 0; // if it has, clear the flag
sesa514652 8:770d168713cc 212
sesa514652 10:42e70b596099 213 // send message over serial port - can observe in CoolTerm etc.
sesa514652 10:42e70b596099 214 printf("Button B pressed\n");
sesa514652 10:42e70b596099 215 }
sesa514652 10:42e70b596099 216 if (g_buttonX_flag){
sesa514652 10:42e70b596099 217 g_buttonX_flag = 0; // if it has, clear the flag
sesa514652 12:ceea378d5691 218 // swap direction when button has been pressed
sesa514652 12:ceea378d5691 219 // (could just use ! but want this to be explicit to aid understanding)
sesa514652 12:ceea378d5691 220 if (direction == UP) {
sesa514652 12:ceea378d5691 221 direction = DOWN;
sesa514652 12:ceea378d5691 222 }
sesa514652 12:ceea378d5691 223 else {
sesa514652 12:ceea378d5691 224 direction = UP;
sesa514652 12:ceea378d5691 225 }
sesa514652 10:42e70b596099 226
sesa514652 10:42e70b596099 227 // send message over serial port - can observe in CoolTerm etc.
sesa514652 10:42e70b596099 228 printf("Button X pressed\n");
sesa514652 10:42e70b596099 229 lcd.clear();
sesa514652 10:42e70b596099 230 lcd.printString("Button Pressed!",0,0);
sesa514652 10:42e70b596099 231 lcd.refresh();
sesa514652 11:1dec05b7d1c1 232 wait(1);
sesa514652 10:42e70b596099 233 }
sesa514652 10:42e70b596099 234 if (g_buttonY_flag){
sesa514652 10:42e70b596099 235 g_buttonY_flag = 0; // if it has, clear the flag
sesa514652 10:42e70b596099 236
sesa514652 10:42e70b596099 237 // send message over serial port - can observe in CoolTerm etc.
sesa514652 10:42e70b596099 238 printf("Button Y pressed\n");
sesa514652 10:42e70b596099 239 }
sesa514652 5:9b2c976ca318 240 Buzzer.play(200,120);
sesa514652 5:9b2c976ca318 241 wait_ms(5);
sesa514652 5:9b2c976ca318 242 Buzzer.play(200,120);
sesa514652 1:757728321abd 243 long distanced = sensor.distance();
sesa514652 1:757728321abd 244 if (distanced >= 400 || distanced <= 2)
sesa514652 5:9b2c976ca318 245 {
sesa514652 1:757728321abd 246 printf("Out of range");
sesa514652 5:9b2c976ca318 247 //Calling dummy function 05/01/22
sesa514652 4:167ce930c9d5 248 int answer = cube(2);
sesa514652 5:9b2c976ca318 249 printf("%f\n",answer);
sesa514652 1:757728321abd 250 wait(1.0);
sesa514652 5:9b2c976ca318 251 }
sesa514652 5:9b2c976ca318 252 else
sesa514652 5:9b2c976ca318 253 {
sesa514652 5:9b2c976ca318 254 printf("Distance : %d cm",distanced);
sesa514652 5:9b2c976ca318 255 wait(1.0); // 1 sec
sesa514652 1:757728321abd 256 }
sesa514652 5:9b2c976ca318 257 lcd.drawCircle(WIDTH/2,HEIGHT/2,distanced,FILL_BLACK);
sesa514652 5:9b2c976ca318 258 //lcd.refresh must be used to update the lcd Display
sesa514652 5:9b2c976ca318 259 lcd.refresh();
sesa514652 5:9b2c976ca318 260 wait(5.0);
sesa514652 5:9b2c976ca318 261 //these are default settings so not strictly needed
sesa514652 0:1f799c7cce2b 262 lcd.normalMode(); // normal colour mode
sesa514652 5:9b2c976ca318 263 lcd.setBrightness(0.5); // put LED backlight on 50%
sesa514652 0:1f799c7cce2b 264 lcd.clear();
sesa514652 0:1f799c7cce2b 265 lcd.printString("Hello, World!",0,0);
sesa514652 0:1f799c7cce2b 266 Vector2D coord = joystick.get_coord();
sesa514652 0:1f799c7cce2b 267 lcd.refresh();
sesa514652 0:1f799c7cce2b 268 printf("Coord = %f,%f\n",coord.x,coord.y);
sesa514652 0:1f799c7cce2b 269 char buffer[14];
sesa514652 0:1f799c7cce2b 270 Vector2D mapped_coord = joystick.get_mapped_coord();
sesa514652 0:1f799c7cce2b 271 printf("Mapped coord = %f,%f\n",mapped_coord.x,mapped_coord.y);
sesa514652 0:1f799c7cce2b 272
sesa514652 5:9b2c976ca318 273 int length = sprintf(buffer,"T = %2f",coord.x);
sesa514652 5:9b2c976ca318 274 //it is important the format specifier ensures the length will fit in the buffer
sesa514652 0:1f799c7cce2b 275 if (length <= 14) // if string will fit on display (assuming printing at x=0)
sesa514652 5:9b2c976ca318 276 lcd.printString(buffer,0,1); // display on screen
sesa514652 0:1f799c7cce2b 277 lcd.refresh();
sesa514652 5:9b2c976ca318 278 lcd.clear();
sesa514652 5:9b2c976ca318 279 //times by 50 to try get the point moving across screen
sesa514652 0:1f799c7cce2b 280 float x50 = mapped_coord.x*5;
sesa514652 0:1f799c7cce2b 281 float y50 = mapped_coord.y*8;
sesa514652 5:9b2c976ca318 282 //to see what the values are
sesa514652 5:9b2c976ca318 283 printf(" *50 = %f,%f\n",x50,y50);
sesa514652 5:9b2c976ca318 284 //example of how to draw circles
sesa514652 1:757728321abd 285 lcd.printChar('o',WIDTH/2,HEIGHT/2);
sesa514652 5:9b2c976ca318 286 lcd.refresh();
sesa514652 0:1f799c7cce2b 287 float mag = joystick.get_mag();
sesa514652 0:1f799c7cce2b 288 float angle = joystick.get_angle();
sesa514652 0:1f799c7cce2b 289 printf("Mag = %f Angle = %f\n",mag,angle);
sesa514652 0:1f799c7cce2b 290 Direction d = joystick.get_direction();
sesa514652 0:1f799c7cce2b 291 printf("Direction = %i\n",d);
sesa514652 0:1f799c7cce2b 292 if (joystick.button_pressed() ) {
sesa514652 0:1f799c7cce2b 293 printf("Button Pressed\n");
sesa514652 9:cdd7d9a123f9 294 wait(5);
sesa514652 0:1f799c7cce2b 295 }
sesa514652 8:770d168713cc 296
sesa514652 8:770d168713cc 297 }
sesa514652 8:770d168713cc 298 }
sesa514652 12:ceea378d5691 299 }
sesa514652 15:234321e80678 300 int buttonCount(){
sesa514652 15:234321e80678 301
sesa514652 15:234321e80678 302 Press++;
sesa514652 15:234321e80678 303 if (Press >3){
sesa514652 15:234321e80678 304 Press = 0;
sesa514652 15:234321e80678 305 }
sesa514652 15:234321e80678 306 return Press;
sesa514652 15:234321e80678 307 }
sesa514652 12:ceea378d5691 308 //Button A event-triggered interrupt
sesa514652 10:42e70b596099 309 void buttonA_isr()
sesa514652 10:42e70b596099 310 {
sesa514652 12:ceea378d5691 311
sesa514652 15:234321e80678 312 buttonCount();
sesa514652 15:234321e80678 313 switch(Press){
sesa514652 15:234321e80678 314 case 1:
sesa514652 15:234321e80678 315 lcd.clear();
sesa514652 15:234321e80678 316 Press = 1;
sesa514652 15:234321e80678 317 lcd.printString("Menu 1",0,0);
sesa514652 15:234321e80678 318 lcd.refresh();
sesa514652 15:234321e80678 319 break;
sesa514652 15:234321e80678 320 case 2:
sesa514652 15:234321e80678 321 Press = 2;
sesa514652 15:234321e80678 322 lcd.clear();
sesa514652 15:234321e80678 323 lcd.printString("Menu 2",0,10);
sesa514652 15:234321e80678 324 lcd.refresh();
sesa514652 15:234321e80678 325 break;
sesa514652 15:234321e80678 326 Press = 3;
sesa514652 15:234321e80678 327 lcd.clear();
sesa514652 15:234321e80678 328 lcd.printString("Menu 3",0,20);
sesa514652 15:234321e80678 329 lcd.refresh();
sesa514652 15:234321e80678 330 break;
sesa514652 15:234321e80678 331 }
sesa514652 12:ceea378d5691 332
sesa514652 12:ceea378d5691 333 g_buttonA_flag = 1; // set flag in ISR
sesa514652 12:ceea378d5691 334
sesa514652 12:ceea378d5691 335 printf("press count = %i\n",Press);
sesa514652 12:ceea378d5691 336
sesa514652 12:ceea378d5691 337 // lcd.clear();
sesa514652 15:234321e80678 338 //lcd.printString("Button A Pressed",0,0);
sesa514652 12:ceea378d5691 339
sesa514652 15:234321e80678 340 // lcd.refresh(); // set flag in ISR
sesa514652 12:ceea378d5691 341 }
sesa514652 12:ceea378d5691 342
sesa514652 11:1dec05b7d1c1 343
sesa514652 10:42e70b596099 344 //Button B event-triggered interrupt
sesa514652 10:42e70b596099 345 void buttonB_isr()
sesa514652 10:42e70b596099 346 {
sesa514652 10:42e70b596099 347 g_buttonB_flag = 1; // set flag in ISR
sesa514652 11:1dec05b7d1c1 348 lcd.clear();
sesa514652 11:1dec05b7d1c1 349 lcd.printString("Button B Pressed",0,0);
sesa514652 11:1dec05b7d1c1 350 lcd.refresh(); // set flag in ISR
sesa514652 10:42e70b596099 351 }
sesa514652 10:42e70b596099 352 //Button X event-triggered interrupt
sesa514652 10:42e70b596099 353 void buttonX_isr()
sesa514652 10:42e70b596099 354 {
sesa514652 10:42e70b596099 355 g_buttonX_flag = 1; // set flag in ISR
sesa514652 11:1dec05b7d1c1 356 lcd.clear();
sesa514652 11:1dec05b7d1c1 357 lcd.printString("Button X Pressed",0,0);
sesa514652 11:1dec05b7d1c1 358 lcd.refresh(); // set flag in ISR
sesa514652 10:42e70b596099 359 }
sesa514652 10:42e70b596099 360 //Button Y event-triggered interrupt
sesa514652 10:42e70b596099 361 void buttonY_isr()
sesa514652 10:42e70b596099 362 {
sesa514652 10:42e70b596099 363 g_buttonY_flag = 1; // set flag in ISR
sesa514652 11:1dec05b7d1c1 364 lcd.clear();
sesa514652 11:1dec05b7d1c1 365 lcd.printString("Button Y Pressed",0,0);
sesa514652 11:1dec05b7d1c1 366 lcd.refresh(); // set flag in ISR
sesa514652 10:42e70b596099 367 }
sesa514652 11:1dec05b7d1c1 368 //Button Start event-triggered interrupt
sesa514652 11:1dec05b7d1c1 369 void buttonStart_isr()
sesa514652 11:1dec05b7d1c1 370 {
sesa514652 11:1dec05b7d1c1 371 g_buttonStart_flag = 1; // set flag in ISR
sesa514652 11:1dec05b7d1c1 372 lcd.clear();
sesa514652 11:1dec05b7d1c1 373 lcd.printString("Button Start Pressed",0,0);
sesa514652 11:1dec05b7d1c1 374 lcd.refresh(); // set flag in ISR
sesa514652 11:1dec05b7d1c1 375 }
sesa514652 11:1dec05b7d1c1 376 //Button Back event-triggered interrupt
sesa514652 11:1dec05b7d1c1 377 void buttonBack_isr()
sesa514652 11:1dec05b7d1c1 378 {
sesa514652 11:1dec05b7d1c1 379 g_buttonBack_flag = 1; // set flag in ISR
sesa514652 11:1dec05b7d1c1 380 lcd.clear();
sesa514652 11:1dec05b7d1c1 381 lcd.printString("Button Back Pressed",0,0);
sesa514652 11:1dec05b7d1c1 382 lcd.refresh(); // set flag in ISR
sesa514652 11:1dec05b7d1c1 383 }
sesa514652 11:1dec05b7d1c1 384 //Button Left event-triggered interrupt
sesa514652 11:1dec05b7d1c1 385 void buttonLeft_isr()
sesa514652 11:1dec05b7d1c1 386 {
sesa514652 11:1dec05b7d1c1 387 g_buttonLeft_flag = 1; // set flag in ISR
sesa514652 11:1dec05b7d1c1 388 lcd.clear();
sesa514652 11:1dec05b7d1c1 389 lcd.printString("Button Left Pressed",0,0);
sesa514652 11:1dec05b7d1c1 390 lcd.refresh(); // set flag in ISR
sesa514652 11:1dec05b7d1c1 391 }
sesa514652 11:1dec05b7d1c1 392 //Button Right event-triggered interrupt
sesa514652 11:1dec05b7d1c1 393 void buttonRight_isr()
sesa514652 11:1dec05b7d1c1 394 {
sesa514652 11:1dec05b7d1c1 395 g_buttonRight_flag = 1; // set flag in ISR
sesa514652 11:1dec05b7d1c1 396 lcd.clear();
sesa514652 11:1dec05b7d1c1 397 lcd.printString("Button Right Pressed",0,0);
sesa514652 11:1dec05b7d1c1 398 lcd.refresh(); // set flag in ISR
sesa514652 11:1dec05b7d1c1 399 }