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

222                          8. INTERMEDIATE LEVEL PROJECTS

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

                                              SOUND LEVEL METER
                                              =================
                      This is a sound level meter project. An electret microphone with an
                      amplifier is connected to analog input PA_0 of the develomet board.
                      The peak-to-peak output voltage of the amplifie is measured and is
                      displayed on the PC screen in millivolts. This reading is proportional
                      to the ambient sound level and needs to be calibrated in dB.
                      Author: Dogan Ibrahim
                      Date  : August 2018
                      File  : SoundLevel
                      **************************************************************************/
                      #include "mbed.h"

                      Serial MyPC(USBTX, USBRX);
                      AnalogIn Sound(PA_0);
                      Timer tim;
                      // Clear the screen
                      //
                      void clrscr()
                      {
                          char clrscr[] = {0x1B, '[', '2' , 'J',0};
                          MyPC.printf(clrscr);
                      }

                      //
                      // 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;
                         float SMax = 0,Peak,SMin = 4096;

                      //
                      // Read the peak-topeak output voltage of the audio amplifier,
                      // then display the voltage on the PC screen
                      //
                         while(1)                                         // Do forever

                 FIG. 8.93  Program listing.
                                                                                          (Continued)
   231   232   233   234   235   236   237   238   239   240   241