Page 126 - ARM Based Microcontroller Projects Using MBED
P. 126

112                       7. USING THE Mbed WITH SIMPLE PROJECTS

                         /****************************************************************

                                         EXTERNAL BUTTON WITH LED
                                         ========================
                         In this program an external button is conencted to GPIO pin PC_0
                         of teh Nucleo-F411RE development board. This button controls the
                         on-board User LED such that when the button is pressed the LED
                         turns ON
                         Author: Dogan Ibrahim
                         Date  : August 2018
                         File  : EXTbutton
                         ******************************************************************/
                         #include "mbed.h"
                         DigitalOut led(LED1);                       // LED is output
                         DigitalIn button(PC_0);                     // Button is input
                         int main()
                         {
                             while(1)                                // Do forever
                             {
                                 if(button == 0)                     // If button pressed
                                     led = 1;                        // LED ON
                                 else
                                     led = 0;                        // LED OFF
                             }
                         }


                 FIG. 7.53  Program listing.





                   PullNone: No pull-up/pull-down resistors
                   OpenDrain: GPIO pin on open-drain mode
                   The earlier modes can either be specified during the declaration of the DigitalIn
                 statement,or later as shown in the following:
                   DigitalIn button(PC_0, PullUp);
                 or as:
                   DigitalIn button(PC_0);
                   button.mode(PullUp);



                 7.13.9 Suggestions for Additional Work
                   Modify the circuit in Fig. 7.50 by removing the external pull-up resistor and enable the in-
                 ternal pull-up resistor on port pin PC_0 in the program as shown in Fig. 7.53.
   121   122   123   124   125   126   127   128   129   130   131