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