Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of Amaldi_2_Exercise_Keyboard_Interrupt by
KeyBoard-Interrupt.cpp@2:39c2ed3c84e3, 2018-05-07 (annotated)
- Committer:
- pinofal
- Date:
- Mon May 07 07:10:08 2018 +0000
- Revision:
- 2:39c2ed3c84e3
Amaldi 2 Exercise
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| pinofal | 2:39c2ed3c84e3 | 1 | // Tested: NUCLEO-L476RG |
| pinofal | 2:39c2ed3c84e3 | 2 | |
| pinofal | 2:39c2ed3c84e3 | 3 | #include "mbed.h" |
| pinofal | 2:39c2ed3c84e3 | 4 | |
| pinofal | 2:39c2ed3c84e3 | 5 | Serial pc(USBTX, USBRX); |
| pinofal | 2:39c2ed3c84e3 | 6 | DigitalOut myLed (LED1); |
| pinofal | 2:39c2ed3c84e3 | 7 | |
| pinofal | 2:39c2ed3c84e3 | 8 | /**************************************/ |
| pinofal | 2:39c2ed3c84e3 | 9 | /* Routine di Gestione Interrupt IRQ */ |
| pinofal | 2:39c2ed3c84e3 | 10 | /**************************************/ |
| pinofal | 2:39c2ed3c84e3 | 11 | void myInterrupt() |
| pinofal | 2:39c2ed3c84e3 | 12 | { |
| pinofal | 2:39c2ed3c84e3 | 13 | char key; |
| pinofal | 2:39c2ed3c84e3 | 14 | |
| pinofal | 2:39c2ed3c84e3 | 15 | // cattura carattere da seriale |
| pinofal | 2:39c2ed3c84e3 | 16 | key = pc.getc(); |
| pinofal | 2:39c2ed3c84e3 | 17 | |
| pinofal | 2:39c2ed3c84e3 | 18 | // invia stringa al PC |
| pinofal | 2:39c2ed3c84e3 | 19 | pc.printf("Interrupted %c\r\n", key); |
| pinofal | 2:39c2ed3c84e3 | 20 | } |
| pinofal | 2:39c2ed3c84e3 | 21 | |
| pinofal | 2:39c2ed3c84e3 | 22 | /********/ |
| pinofal | 2:39c2ed3c84e3 | 23 | /* MAIN */ |
| pinofal | 2:39c2ed3c84e3 | 24 | /********/ |
| pinofal | 2:39c2ed3c84e3 | 25 | int main() |
| pinofal | 2:39c2ed3c84e3 | 26 | { |
| pinofal | 2:39c2ed3c84e3 | 27 | // inizializza seriale |
| pinofal | 2:39c2ed3c84e3 | 28 | pc.baud(921600); |
| pinofal | 2:39c2ed3c84e3 | 29 | |
| pinofal | 2:39c2ed3c84e3 | 30 | // inizializza variabili |
| pinofal | 2:39c2ed3c84e3 | 31 | myLed=0; |
| pinofal | 2:39c2ed3c84e3 | 32 | |
| pinofal | 2:39c2ed3c84e3 | 33 | // messaggio di benvenuto |
| pinofal | 2:39c2ed3c84e3 | 34 | pc.printf("\r\nHallo Amaldi Students - Exercise 2 \r\n"); |
| pinofal | 2:39c2ed3c84e3 | 35 | |
| pinofal | 2:39c2ed3c84e3 | 36 | // inizializza routine interrupt |
| pinofal | 2:39c2ed3c84e3 | 37 | pc.attach(myInterrupt, Serial::RxIrq); |
| pinofal | 2:39c2ed3c84e3 | 38 | |
| pinofal | 2:39c2ed3c84e3 | 39 | // accendi/spegni LED mentre attende Rx da seriale per gestire la IRQ |
| pinofal | 2:39c2ed3c84e3 | 40 | while(1) |
| pinofal | 2:39c2ed3c84e3 | 41 | { |
| pinofal | 2:39c2ed3c84e3 | 42 | // inverte lo stato acceso/spento del LED |
| pinofal | 2:39c2ed3c84e3 | 43 | myLed=!myLed; |
| pinofal | 2:39c2ed3c84e3 | 44 | } |
| pinofal | 2:39c2ed3c84e3 | 45 | } |
