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
Diff: LED-Button-Polling.cpp
- Revision:
- 3:042d47e3c101
- Parent:
- 2:8cd95bea99dc
diff -r 8cd95bea99dc -r 042d47e3c101 LED-Button-Polling.cpp
--- a/LED-Button-Polling.cpp Sun Jul 01 11:30:52 2018 +0000
+++ b/LED-Button-Polling.cpp Wed Jun 01 10:40:15 2022 +0000
@@ -5,7 +5,13 @@
// crea oggetti Button, LED e serialPC
DigitalIn myButton(USER_BUTTON);
DigitalOut myLed(LED1);
-Serial pc(USBTX, USBRX);
+DigitalIn InMIMA(PA_0); //PC_1; PB_0; PA_1; PA_0
+DigitalOut OutSC(PC_0);
+DigitalIn InSC(PA_10);
+DigitalOut OutMIMA(PA_9); //PB_3; PB_6; PC_7; PA_9
+
+
+Serial pc(USBTX, USBRX, 921600);
/********/
@@ -13,28 +19,57 @@
/********/
int main()
{
- // imposta velocità della comunicazione con il PC
- pc.baud(921600);
+ // messaggio di benvenuto
+ pc.printf("\r\nHello World \r\n");
+ myLed = 1; // Accendi LED
+ wait_ms(1000);
+ myLed = 0; // Accendi LED
+ wait_ms(1000);
+
- // messaggio di benvenuto
- pc.printf("\r\nHallo Amaldi Students - Exercise 3 \r\n");
-
//imposta il funzionamento del pulsante come "PullDown": Aperto = '0'. L'altra modalità di funzinamento è PullUp
- myButton.mode(PullDown);
+ myButton.mode(PullUp);
+ InMIMA.mode(PullUp);
+ InSC.mode(PullUp);
// POLLING: replica sul LED myLED lo stato del pulsante myButton
while(true)
{
- if (myButton == 1)
- {
+ //+++++ INIZIO Comunicazione da STM32 verso MIMA ++++++++++++++
+ OutSC=myButton;
+ if (InMIMA == 0)
+ {
// Button is pressed
myLed = 1; // Accendi LED
+ pc.printf("InMIMA = 0 \r\n");
}
else
{
// Button i released
myLed = 0; // Spegni LED
+ pc.printf("InMIMA = 1 \r\n");
}
+ //+++++ FINE Comunicazione da STM32 verso MIMA ++++++++++++++
+
+ //+++++ INIZIO Comunicazione da S/C verso STM32 ++++++++++++++
+ OutMIMA=myButton;
+ if (InSC == 0)
+ {
+ // Button is pressed
+ myLed = 1; // Accendi LED
+ pc.printf("InSC = 0 \r\n");
+ }
+ else
+ {
+ // Button i released
+ myLed = 0; // Spegni LED
+ pc.printf("InSC = 1 \r\n");
+ }
+ //+++++ FINE Comunicazione da S/C verso STM32 ++++++++++++++
+
+ pc.printf("\r\n"); // per facilità di lettura
+ wait_ms(200);
+
}
-}
-
\ No newline at end of file
+
+ }
\ No newline at end of file