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

182                          8. INTERMEDIATE LEVEL PROJECTS

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

                                            EVENT COUNTER
                                            =============
                        In this program teh user button is used to simulate the occurence
                        of external events. Every time the button is pressed a count is
                        incremented by one. The total count is displayed on the PC screen.
                        Author: Dogan Ibrahim
                        Date  : August 2018
                        File  : SerialEvents
                        ********************************************************************/
                        #include "mbed.h"
                        Serial MyPC(USBTX, USBRX);
                        DigitalIn button(BUTTON1);

                        //
                        // Clear the screen
                        //
                        void clrscr()
                        {
                            char clrscr[] = {0x1B, '[', '2' , 'J',0};
                            MyPC.printf(clrscr);
                        }
                        //
                        // Home the cursor
                        //
                        void homescr()
                        {
                            char homescr[] = {0x1B, '[' , 'H' , 0};
                            MyPC.printf(homescr);
                        }
                        //
                        // Goto specified line and column
                        //
                        void gotoscr(int line, int column)
                        {
                            char scr[] = {0x1B, '[', 0x00, ';' ,0x00, 'H', 0};
                            scr[2] = line;
                            scr[4] = column;
                            MyPC.printf(scr);
                        }


                        int main()
                        {
                           int Count = 0;                               // Initialzie Count

                           clrscr();                                    // Clear the screen
                           homescr();                                   // Home the cursor
                           MyPC.printf("\n\rEvent Counter");            // Display heading
                           MyPC.printf("\n\r==============\n\r");
                 FIG. 8.44  Program listing.
                                                                                          (Continued)
   191   192   193   194   195   196   197   198   199   200   201