FalaFam / Mbed 2 deprecated Amaldi_2_Exercise_Keyboard_Interrupt

Dependencies:   mbed

Fork of Amaldi_2_Exercise_Keyboard_Interrupt by Amaldi

Revision:
2:39c2ed3c84e3
diff -r 5440b3d7f435 -r 39c2ed3c84e3 KeyBoard-Interrupt.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/KeyBoard-Interrupt.cpp	Mon May 07 07:10:08 2018 +0000
@@ -0,0 +1,45 @@
+// Tested: NUCLEO-L476RG
+
+#include "mbed.h"
+
+Serial pc(USBTX, USBRX);
+DigitalOut myLed (LED1);
+
+/**************************************/
+/* Routine di Gestione Interrupt IRQ  */
+/**************************************/
+void myInterrupt()
+{
+    char key;
+    
+    // cattura carattere da seriale
+    key = pc.getc();
+    
+    // invia stringa al PC
+    pc.printf("Interrupted %c\r\n", key);
+}
+
+/********/
+/* MAIN */
+/********/
+int main() 
+{
+    // inizializza seriale
+    pc.baud(921600);
+    
+    // inizializza variabili
+    myLed=0;
+    
+    // messaggio di benvenuto
+    pc.printf("\r\nHallo Amaldi Students - Exercise 2 \r\n");
+    
+    // inizializza routine interrupt
+    pc.attach(myInterrupt, Serial::RxIrq);
+    
+    // accendi/spegni LED mentre attende Rx da seriale per gestire la IRQ
+    while(1)
+    {
+        // inverte lo stato acceso/spento del LED
+        myLed=!myLed;   
+    }
+}