FalaFam / Mbed 2 deprecated Amaldi_3_Exercise_LED-Button_Polling

Dependencies:   mbed

Fork of Amaldi_3_Exercise_LED-Button_Polling by Amaldi

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LED-Button-Polling.cpp Source File

LED-Button-Polling.cpp

00001 // Tested: NUCLE-L476RG
00002 
00003 #include "mbed.h"
00004 
00005 // crea oggetti Button, LED e serialPC  
00006 DigitalIn myButton(USER_BUTTON);
00007 DigitalOut myLed(LED1);
00008 Serial pc(USBTX, USBRX); 
00009 
00010 
00011 /********/
00012 /* MAIN */
00013 /********/
00014 int main() 
00015 {
00016     // imposta velocità della comunicazione con il PC
00017     pc.baud(921600);
00018     
00019     // messaggio di benvenuto
00020     pc.printf("\r\nHallo Amaldi Students - Exercise 3 \r\n");
00021   
00022     //imposta il funzionamento del pulsante come "PullDown": Aperto = '0'. L'altra modalità di funzinamento è PullUp
00023     myButton.mode(PullDown);
00024   
00025     // POLLING: replica sul LED myLED lo stato del pulsante myButton
00026     while(true) 
00027     {
00028         if (myButton == 1) 
00029         { 
00030             // Button is pressed
00031             myLed = 1; // Accendi LED
00032         }
00033         else 
00034         {
00035             // Button i released
00036             myLed = 0; // Spegni LED
00037         }
00038     }
00039 }
00040