![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Coursework
Diff: main.cpp
- Revision:
- 18:bb36d96142dd
- Parent:
- 16:2646c1c4e62e
- Child:
- 19:32f9fc794ef8
- Child:
- 20:4e1f2917a857
--- a/main.cpp Thu Jan 13 20:53:37 2022 +0000 +++ b/main.cpp Sat Jan 15 23:02:39 2022 +0000 @@ -15,7 +15,8 @@ // array of states in the FSM, each element is the output of the counter // set the output in binary to make it easier, 0 is LED on, 1 is LED off string fsm[4] = {"buttonA_isr","buttonB_isr","buttonAsss_isr","buttonA_isr"}; -volatile int Press; +volatile int PressA; +volatile int PressB; // y x button Joystick joystick(PTB10,PTB11,PTC16); @@ -62,7 +63,8 @@ volatile int g_buttonBack_flag = 0; // Global Flag volatile int g_buttonLeft_flag = 0; // Global Flag volatile int g_buttonRight_flag = 0; // Global Flag -int buttonCounter(); +int buttonCountA(); +int buttonCountB(); //volatile int g_buttonA_counter = 0; // Global counter //Test function after research C++ lanuage 05/01/22 int cube(int num){ @@ -97,7 +99,7 @@ // return num*num; // }; int main() { -//initialise Joystic +//initialise Joystick joystick.init(); // create a thread that'll run the event queue's dispatch function @@ -132,14 +134,7 @@ // Button Right is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister buttonRight.mode(PullDown); -// It will return 0 by default and a 1 when pressed i.e. cause a rising edge - // buttonA.rise(&buttonA_isr); - // It will return 0 by default and a 1 when pressed i.e. cause a rising edge - // buttonB.rise(&buttonB_isr); - // It will return 0 by default and a 1 when pressed i.e. cause a rising edge - //buttonX.rise(&buttonX_isr); - // It will return 0 by default and a 1 when pressed i.e. cause a rising edge - // buttonY.rise(&buttonY_isr); + @@ -173,50 +168,8 @@ Object1.te = 'A'; Object1.dubs = 23; Object1.namestruct = "name"; -//buttonA.rise(&buzzme); Omitted due to error -//buttonA.rise(&printme,10); -//buttonA.rise(&returnme); + while(1) { -//Tune(Buzzer,So6,8); -//Stop_tunes(Buzzer); -//Section of code to try to get the button press to be recorded -//bool button = buttonA.read(); -//printf("%f\n", g_buttonA_flag ); -//Recording button presses - - // swap direction when button has been pressed - // (could just use ! but want this to be explicit to aid understanding) - if (direction == UP) { - direction = DOWN; - } - else { - direction = UP; - - //output = fsm[state]; - switch(Press){ - case 1: - lcd.clear(); - Press = 1; - lcd.printString("Menu 1",0,0); - lcd.refresh(); - break; - case 2: - Press = 2; - lcd.clear(); - lcd.printString("Menu 2",0,0); - lcd.refresh(); - break; - Press = 0; - lcd.clear(); - lcd.printString("Menu 4",0,0); - lcd.refresh(); - break; - } - -/* -int result; - result = cube(5); - printf("Button A pressed %f\n", cube(5)); int button_counter; if (g_buttonA_flag){ button_counter = button_counter +1; @@ -314,28 +267,63 @@ } } - }*/ } - } - } - int buttonCount(){ + + + + int buttonCountA(){ + PressA++; + if (PressA>3){ + PressA= 0; + } + return PressA; + } + int buttonCountB(){ + PressB++; + if (PressB>3){ + PressB= 0; + } + return PressB; + } - Press++; - if (Press >3){ - Press = 0; - } - return Press; - } //Button A event-triggered interrupt void buttonA_isr() { - buttonCount(); + long distanced = sensor.distance(); + buttonCountA(); + switch(PressA){ + case 1: + PressA= 1; + for(int i = 0; i < 5; i++){ + + lcd.clear(); + lcd.printString("Menu 1",0,0); + lcd.refresh(); + lcd.drawCircle(WIDTH/2,HEIGHT/2,distanced,FILL_BLACK); + lcd.refresh();} + + break; + + case 2: + PressA= 2; + lcd.clear(); + lcd.printString("Menu 2",0,0); + lcd.refresh(); + break; + case 3: + PressA= 3; + lcd.clear(); + lcd.printString("Menu 3",0,0); + lcd.refresh(); + break; + } + g_buttonA_flag = 1; // set flag in ISR - printf("press count = %i\n",Press); + printf("press count = %i\n",PressA); // lcd.clear(); //lcd.printString("Button A Pressed",0,0); @@ -347,10 +335,12 @@ //Button B event-triggered interrupt void buttonB_isr() { + buttonCountB(); g_buttonB_flag = 1; // set flag in ISR lcd.clear(); lcd.printString("Button B Pressed",0,0); lcd.refresh(); // set flag in ISR + printf("press count = %i\n",PressB); } //Button X event-triggered interrupt void buttonX_isr()