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

104                       7. USING THE Mbed WITH SIMPLE PROJECTS

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

                                            PUSH BUTTON WITH LED
                                            ====================
                        In this program teh user Button (BUTTON1) and the User LED (LED1)
                        are used. When the button is pressed the LED flashed 3 times with
                        one second delay between each output.
                        Author: Dogan Ibrahim
                        Date  : August 2018
                        File  : Push
                        **********************************************************************/
                        #include "mbed.h"
                        DigitalOut led(LED1);                           // LED1 isoutput
                        DigitalIn button(BUTTON1);                      // BUTTON1 is input

                        int main()
                        {
                            while(1)                                    // DO forever
                            {
                                if(button == 0)                         // If button is pressed
                                {
                                    for(int k = 0; k < 3; k++)          // Do 3 times
                                    {
                                        led = 1;                        // LED ON
                                        wait(1.0);                      // Wait 1 second
                                        led = 0;                        // LED OFF
                                        wait(1.0);                      // Wait 1 second
                                    }
                                }
                            }
                        }

                 FIG. 7.40  Program listing.

                           7.11 PROJECT 8—CHANGING LED FLASHING RATE

                 7.11.1 Description
                   In this project the user push-button and the user LED on the Nucleo-F411RE development
                 board are used. The LED flashing rate is changed every time the button is pressed. This is
                 done by changing the delay between the flashes.


                 7.11.2 Aim

                   The aim of this project is to show how the user push-button on the Nucleo board can
                 be used.
   113   114   115   116   117   118   119   120   121   122   123