mid

Dependencies:   mbed

Revision:
0:9a525a0d1d3f
diff -r 000000000000 -r 9a525a0d1d3f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Apr 27 12:01:16 2020 +0000
@@ -0,0 +1,61 @@
+#include "mbed.h"
+#include "N5110.h"
+
+N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); 
+
+InterruptIn buttonL(PTB18);
+InterruptIn buttonR(PTB3);
+
+// g_ prefix makes it easier to distinguish it as global
+volatile int g_buttonL_flag = 0;
+volatile int g_buttonR_flag = 0;
+// Button L&R interrupt service routine
+void buttonL_isr();
+void buttonR_isr();
+
+int main() {
+
+   lcd.init();
+
+   // Button L&R is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister
+    buttonL.mode(PullDown);
+    buttonR.mode(PullDown);
+    // It will return 0 by default and a 1 when pressed i.e. cause a rising edge
+    buttonL.rise(&buttonL_isr);
+    buttonR.rise(&buttonR_isr);
+    
+    int p=20, q=3;      //位置
+    int a=2, b=1;       //步长
+    
+   while(1) {
+       
+       lcd.clear();
+       lcd.printString("Hello!",p,q);
+       
+       if (g_buttonL_flag) {
+            p=p-a;
+            q=q-b;
+            g_buttonL_flag = 0;  // if it has, clear the flag
+        }
+        
+        if (g_buttonR_flag) {
+            p=p+a;
+            q=q+b;
+            g_buttonR_flag = 0;  // if it has, clear the flag
+        }
+        
+       lcd.refresh();         
+       wait(0.1);
+   }
+   
+}
+
+void buttonL_isr()
+{
+    g_buttonL_flag = 1;   // set flag in ISR
+}
+
+void buttonR_isr()
+{
+    g_buttonR_flag = 1;   // set flag in ISR
+}
\ No newline at end of file