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

108                       7. USING THE Mbed WITH SIMPLE PROJECTS

                                  BEGIN
                                        Configure and group LEDs as outputs
                                        Configure button as input
                                        Cnt = 0
                                        Turn OFF all LEDs at the beginning
                                        DO FOREVER
                                              IF button is pressed THEN
                                                     Increment CNT
                                                     Display CNT on LEDs in binary
                                              ENDIF
                                        ENDDO
                                  END
                 FIG. 7.45  PDL of the program.



                    /*****************************************************************************
                                BINARY EVENT COUNTER WITH LEDS
                                ==============================
                    In this program 8 LEDs are connected to lower byte of PORT C. The program
                    simulates an ebent counter such that when the User button is pressed a
                    count is incremented by one and is then displayed on the LEDs.

                    Author: Dogan Ibrahim
                    Date  : August 2018
                    File  : Events
                    ***************************************************************************/
                    #include "mbed.h"
                    BusOut LEDS(PC_0,PC_1,PC_2,PC_3,PC_4,PC_5,PC_6,PC_7);
                    DigitalIn button(BUTTON1);

                    int main()
                    {
                        int Cnt = 0;                                // Cnt = 0 to start with
                        LEDS = 0;                                   // All LEDs OFF at beginning

                        while(1)                                    // DO Forever
                        {
                            if(button == 0)                         // If button is pressed
                            {
                                Cnt++;                              // Increment Cnt
                                LEDS = Cnt;                         // Display Cnt
                                while(button == 0);                 // Wait until button released
                            }
                        }
                    }


                 FIG. 7.46  Program listing.
   117   118   119   120   121   122   123   124   125   126   127