ADC -> LCD

Dependencies:   SLCD mbed-src

Committer:
mattshuman
Date:
Sat Jul 15 16:49:37 2017 +0000
Revision:
0:846020faea19
Initial ADC project;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mattshuman 0:846020faea19 1 /*! Lab2
mattshuman 0:846020faea19 2 * Used to turn the FRDM-KL46Z into a voltmeter.
mattshuman 0:846020faea19 3 * Modified from: https://developer.mbed.org/users/star297/code/FRDM-KL46Z-LCD-rtc-Demo/
mattshuman 0:846020faea19 4 * \author Matthew Shuman
mattshuman 0:846020faea19 5 *
mattshuman 0:846020faea19 6 * \date August 28th, 2016
mattshuman 0:846020faea19 7
mattshuman 0:846020faea19 8 * \bug No bugs yet
mattshuman 0:846020faea19 9
mattshuman 0:846020faea19 10 * @code
mattshuman 0:846020faea19 11 * #include "mbed.h"
mattshuman 0:846020faea19 12 * #include "SLCD.h"
mattshuman 0:846020faea19 13
mattshuman 0:846020faea19 14 * SLCD myLcd;
mattshuman 0:846020faea19 15 * int myNumber=0;
mattshuman 0:846020faea19 16 * int main()
mattshuman 0:846020faea19 17 * {
mattshuman 0:846020faea19 18 * while(1) {
mattshuman 0:846020faea19 19 * myLcd.printf("00%2.0i",myNumber);
mattshuman 0:846020faea19 20 * ++myNumber;
mattshuman 0:846020faea19 21 * wait(.1);
mattshuman 0:846020faea19 22 * }//end of while
mattshuman 0:846020faea19 23 * }//end of main
mattshuman 0:846020faea19 24 * @endcode
mattshuman 0:846020faea19 25 */
mattshuman 0:846020faea19 26
mattshuman 0:846020faea19 27
mattshuman 0:846020faea19 28 #include "mbed.h"
mattshuman 0:846020faea19 29 #include "SLCD.h"
mattshuman 0:846020faea19 30
mattshuman 0:846020faea19 31 SLCD slcd; //Setup the LCD on the FRDM-KL46Z.
mattshuman 0:846020faea19 32 DigitalOut led1(LED1); //Setup the green LED.
mattshuman 0:846020faea19 33 AnalogIn ReadVoltage(A0); //Setup the analog input.
mattshuman 0:846020faea19 34 DigitalOut SpeakerOut(PTE30);
mattshuman 0:846020faea19 35 //AnalogOut SpeakerOut(PTE30);
mattshuman 0:846020faea19 36
mattshuman 0:846020faea19 37 main()
mattshuman 0:846020faea19 38 {
mattshuman 0:846020faea19 39
mattshuman 0:846020faea19 40 //Add a pull up resistor to SW1.
mattshuman 0:846020faea19 41 led1 = 0; //Turn on the green LED.
mattshuman 0:846020faea19 42 slcd.DP1(1); //Turn on the decimal point
mattshuman 0:846020faea19 43 SpeakerOut = 0;
mattshuman 0:846020faea19 44
mattshuman 0:846020faea19 45 while(1) {
mattshuman 0:846020faea19 46 led1=!led1; //Toggle the green LED
mattshuman 0:846020faea19 47 slcd.printf("%4.0f", ReadVoltage.read()*3300.f); //Use this line to read the analog input.
mattshuman 0:846020faea19 48 wait_ms(ReadVoltage.read()*10); //Wait some time
mattshuman 0:846020faea19 49 SpeakerOut =! SpeakerOut;
mattshuman 0:846020faea19 50
mattshuman 0:846020faea19 51 // SpeakerOut = 0;
mattshuman 0:846020faea19 52 // wait_ms(1);
mattshuman 0:846020faea19 53 // SpeakerOut = .25;
mattshuman 0:846020faea19 54 // wait_ms(1);
mattshuman 0:846020faea19 55 // SpeakerOut = .50;
mattshuman 0:846020faea19 56 // wait_ms(1);
mattshuman 0:846020faea19 57 // SpeakerOut = .75;
mattshuman 0:846020faea19 58 // wait_ms(1);
mattshuman 0:846020faea19 59 // SpeakerOut = 1;
mattshuman 0:846020faea19 60 // wait_ms(1);
mattshuman 0:846020faea19 61
mattshuman 0:846020faea19 62 }
mattshuman 0:846020faea19 63 }