![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Coursework
Diff: main.cpp
- Revision:
- 10:42e70b596099
- Parent:
- 9:cdd7d9a123f9
- Child:
- 11:1dec05b7d1c1
--- a/main.cpp Thu Jan 06 21:58:39 2022 +0000 +++ b/main.cpp Fri Jan 07 12:09:52 2022 +0000 @@ -4,6 +4,7 @@ #include "hcsr04.h" #include "Piezo.h" #include "string" + // y x button Joystick joystick(PTB10,PTB11,PTC16); HCSR04 sensor(D14, D15); @@ -28,14 +29,29 @@ void init_K64F(); // Button A interrupt service routine void buttonA_isr(); +// Button B interrupt service routine +void buttonB_isr(); +// Button X interrupt service routine +void buttonX_isr(); +// Button Y interrupt service routine +void buttonY_isr(); volatile int g_buttonA_flag = 0; +volatile int g_buttonB_flag = 0; +volatile int g_buttonX_flag = 0; +volatile int g_buttonY_flag = 0; //Test function after research C++ lanuage 05/01/22 int cube(int num){ int result; result = num*num; return result; }; - +// Menu Items +int page1; +int page2; +int page3; +string Listitem1 = "Game"; // guess distance +string Listitem2 = "Measure"; // measure distance of object +string Listitem3 = "Detect"; // alarm when object is dectected N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); /* Test of the interup an operating the buzzer this kills the board void buzzme(){ @@ -44,10 +60,19 @@ Buzzer.play(200,120);; } */ - void printme(){ + double printme(){ - printf("A Pressed"); + double x ; + x = 1; + printf("%f\n",x); + return 0; } + + +//void returnme(){ +//int num; + // return num*num; + // }; int main() { //initialise Joystic joystick.init(); @@ -57,9 +82,21 @@ // Button A is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister buttonA.mode(PullDown); + // Button B is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister + buttonB.mode(PullDown); + // Button X is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister + buttonX.mode(PullDown); + // Button Y is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister + buttonY.mode(PullDown); // It will return 0 by default and a 1 when pressed i.e. cause a rising edge - // buttonA.rise(&buttonA_isr); + 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); @@ -79,7 +116,7 @@ // string ; }; // Test Class 06/01/22 -class myClass{ + class myClass{ public: string nameclass ; double dubss; @@ -87,21 +124,50 @@ }; myClass Class1; Class1.nameclass ="firstclass"; - ObjectDefine Object1; -Object1.qwer = 12; + ObjectDefine Object1; + Object1.qwer = 12; Object1.Distance = 34; Object1.te = 'A'; Object1.dubs = 23; - Object1.namestruct = "name"; + Object1.namestruct = "name"; //buttonA.rise(&buzzme); Omitted due to error -buttonA.rise(&printme); +//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 ); +//printf("%f\n", g_buttonA_flag ); +//Recording button presses +if (g_buttonA_flag){ + g_buttonA_flag = 0; // if it has, clear the flag + + // send message over serial port - can observe in CoolTerm etc. + printf("Button A pressed\n"); + } +if (g_buttonB_flag){ + g_buttonB_flag = 0; // if it has, clear the flag + // send message over serial port - can observe in CoolTerm etc. + printf("Button B pressed\n"); + } +if (g_buttonX_flag){ + g_buttonX_flag = 0; // if it has, clear the flag + + // send message over serial port - can observe in CoolTerm etc. + printf("Button X pressed\n"); + lcd.clear(); + lcd.printString("Button Pressed!",0,0); + lcd.refresh(); + wait(10); + } +if (g_buttonY_flag){ + g_buttonY_flag = 0; // if it has, clear the flag + + // send message over serial port - can observe in CoolTerm etc. + printf("Button Y pressed\n"); + } Buzzer.play(200,120); wait_ms(5); Buzzer.play(200,120); @@ -161,8 +227,25 @@ } } - // Button A event-triggered interrupt -//void buttonA_isr() -//{ - // g_buttonA_flag = 1; // set flag in ISR -//} + + + //Button A event-triggered interrupt +void buttonA_isr() +{ + g_buttonA_flag = 1; // set flag in ISR +} + //Button B event-triggered interrupt +void buttonB_isr() +{ + g_buttonB_flag = 1; // set flag in ISR +} + //Button X event-triggered interrupt +void buttonX_isr() +{ + g_buttonX_flag = 1; // set flag in ISR +} + //Button Y event-triggered interrupt +void buttonY_isr() +{ + g_buttonY_flag = 1; // set flag in ISR +}