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

8.25  PROJECT 21—CHANGING LED FLASHING RATE WITH A POTENTIOMETER  215
                /*************************************************************************

                                        LIGHT LEVEL METER
                                        =================
                This is a light level meter project. A light dependent resistor is
                connected to one of the analog inputs of the development board. The
                project displays the light level in lux on the PC screen.
                Author: Dogan Ibrahim
                Date  : August 2018
                File  : LDR
                **************************************************************************/
                #include "mbed.h"
                Serial MyPC(USBTX, USBRX);
                AnalogIn LDR(PA_0);

                // 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()
                {
                   double mV, R, lux;

                   clrscr();                                        // Clear the screen
                   homescr();                                       // Home the cursor
                   MyPC.printf("\n\rLIGHT LEVEL METER");            // Display heading
                   MyPC.printf("\n\r=================");
            FIG. 8.83  Program listing.
                                                                                     (Continued)
   224   225   226   227   228   229   230   231   232   233   234