ADC -> LCD

Dependencies:   SLCD mbed-src

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*! Lab2
00002  *  Used to turn the FRDM-KL46Z into a voltmeter.
00003  *  Modified from: https://developer.mbed.org/users/star297/code/FRDM-KL46Z-LCD-rtc-Demo/
00004  * \author  Matthew Shuman
00005  *
00006  * \date    August 28th, 2016
00007 
00008  * \bug     No bugs yet
00009 
00010  * @code
00011  * #include "mbed.h"
00012  * #include "SLCD.h"
00013 
00014  * SLCD myLcd;
00015  * int myNumber=0;
00016  * int main()
00017  * {
00018  *     while(1) {
00019  *        myLcd.printf("00%2.0i",myNumber);
00020  *        ++myNumber;
00021  *         wait(.1);
00022  *     }//end of while
00023  * }//end of main
00024  * @endcode
00025  */
00026 
00027 
00028 #include "mbed.h"
00029 #include "SLCD.h"
00030 
00031 SLCD slcd;                          //Setup the LCD on the FRDM-KL46Z.
00032 DigitalOut  led1(LED1);             //Setup the green LED.
00033 AnalogIn    ReadVoltage(A0);        //Setup the analog input.
00034 DigitalOut  SpeakerOut(PTE30);
00035 //AnalogOut   SpeakerOut(PTE30); 
00036 
00037 main()
00038 {
00039    
00040             //Add a pull up resistor to SW1.
00041     led1 = 0;                       //Turn on the green LED.
00042     slcd.DP1(1);                    //Turn on the decimal point
00043     SpeakerOut = 0;
00044     
00045     while(1) {
00046         led1=!led1;                     //Toggle the green LED
00047         slcd.printf("%4.0f", ReadVoltage.read()*3300.f);  //Use this line to read the analog input.
00048         wait_ms(ReadVoltage.read()*10);                  //Wait some time
00049         SpeakerOut =! SpeakerOut;
00050         
00051 //        SpeakerOut = 0;
00052 //        wait_ms(1);
00053 //        SpeakerOut = .25;
00054 //        wait_ms(1);
00055 //        SpeakerOut = .50;
00056 //        wait_ms(1);
00057 //        SpeakerOut = .75;
00058 //        wait_ms(1);
00059 //        SpeakerOut = 1;
00060 //        wait_ms(1);
00061 
00062     }
00063 }