Coursework

Revision:
8:770d168713cc
Parent:
7:ce70a873aa70
Child:
9:cdd7d9a123f9
--- a/main.cpp	Thu Jan 06 11:00:39 2022 +0000
+++ b/main.cpp	Thu Jan 06 20:42:44 2022 +0000
@@ -3,11 +3,16 @@
 #include "N5110.h"
 #include "hcsr04.h"
 #include "Piezo.h"
-#include<string>
+#include "string"
 // y  x  button
 Joystick joystick(PTB10,PTB11,PTC16);
 HCSR04 sensor(D14, D15); 
 Piezo Buzzer(PTC10);
+//Bringing in buttons
+InterruptIn buttonA(PTB9);
+InterruptIn buttonB(PTD0);
+InterruptIn buttonX(PTC17);
+InterruptIn buttonY(PTC12);
 
 //rows,cols
 int sprite[8][5] =   {
@@ -20,8 +25,11 @@
     { 1,1,0,1,1 },
     { 1,1,0,1,1 },
       };
-
-//Test Void after research C++ lanuage 05/01/22
+      void init_K64F();
+// Button A interrupt service routine
+void buttonA_isr();
+volatile int g_buttonA_flag = 0;
+//Test function after research C++ lanuage 05/01/22
 int cube(int num){
      int result;
      result = num*num;
@@ -36,6 +44,14 @@
        
 //first need to initialise display
        lcd.init();    
+
+// 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);
+    
+// It will return 0 by default and a 1 when pressed i.e. cause a rising edge
+    buttonA.rise(&buttonA_isr);
+
+
        
 //change set contrast in range 0.0 to 1.0
 //0.5 appears to be a good starting point
@@ -50,7 +66,7 @@
     char te;
     double dubs;
  string namestruct;
-    string ;
+   // string ;
 };
 // Test Class 06/01/22
 class myClass{
@@ -70,6 +86,10 @@
     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 );
+
        Buzzer.play(200,120);
             wait_ms(5);
        Buzzer.play(200,120);
@@ -125,6 +145,11 @@
         if (joystick.button_pressed() ) {
             printf("Button Pressed\n");  
         }
-    }
-}
-          
\ No newline at end of file
+    
+    }  
+ }
+ // Button A event-triggered interrupt
+void buttonA_isr()
+{
+    g_buttonA_flag = 1;   // set flag in ISR
+}
\ No newline at end of file