This is the initial commit for the voltmeter used in Lab 2.
Fork of FRDM-KL46Z LCD rtc Demo by
main.cpp@3:b3b886fc6cf3, 2016-09-30 (annotated)
- Committer:
- ziadeldebri
- Date:
- Fri Sep 30 03:52:24 2016 +0000
- Revision:
- 3:b3b886fc6cf3
- Parent:
- 2:eb8f263cccdb
Simpler to explain.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mattshuman | 2:eb8f263cccdb | 1 | /*! Lab2 |
mattshuman | 2:eb8f263cccdb | 2 | * Used to turn the FRDM-KL46Z into a voltmeter. |
mattshuman | 2:eb8f263cccdb | 3 | * Modified from: https://developer.mbed.org/users/star297/code/FRDM-KL46Z-LCD-rtc-Demo/ |
mattshuman | 2:eb8f263cccdb | 4 | * \author Matthew Shuman |
mattshuman | 2:eb8f263cccdb | 5 | * |
mattshuman | 2:eb8f263cccdb | 6 | * \date August 28th, 2016 |
mattshuman | 2:eb8f263cccdb | 7 | |
mattshuman | 2:eb8f263cccdb | 8 | * \bug No bugs yet |
mattshuman | 2:eb8f263cccdb | 9 | |
mattshuman | 2:eb8f263cccdb | 10 | * @code |
mattshuman | 2:eb8f263cccdb | 11 | * #include "mbed.h" |
mattshuman | 2:eb8f263cccdb | 12 | * #include "SLCD.h" |
mattshuman | 2:eb8f263cccdb | 13 | |
mattshuman | 2:eb8f263cccdb | 14 | * SLCD myLcd; |
mattshuman | 2:eb8f263cccdb | 15 | * int myNumber=0; |
mattshuman | 2:eb8f263cccdb | 16 | * int main() |
mattshuman | 2:eb8f263cccdb | 17 | * { |
mattshuman | 2:eb8f263cccdb | 18 | * while(1) { |
mattshuman | 2:eb8f263cccdb | 19 | * myLcd.printf("00%2.0i",myNumber); |
mattshuman | 2:eb8f263cccdb | 20 | * ++myNumber; |
mattshuman | 2:eb8f263cccdb | 21 | * wait(.1); |
mattshuman | 2:eb8f263cccdb | 22 | * }//end of while |
mattshuman | 2:eb8f263cccdb | 23 | * }//end of main |
mattshuman | 2:eb8f263cccdb | 24 | * @endcode |
mattshuman | 2:eb8f263cccdb | 25 | */ |
mattshuman | 2:eb8f263cccdb | 26 | |
mattshuman | 2:eb8f263cccdb | 27 | |
star297 | 0:4f67859595b2 | 28 | #include "mbed.h" |
star297 | 0:4f67859595b2 | 29 | #include "SLCD.h" |
star297 | 0:4f67859595b2 | 30 | |
mattshuman | 2:eb8f263cccdb | 31 | SLCD slcd; //Setup the LCD on the FRDM-KL46Z. |
mattshuman | 2:eb8f263cccdb | 32 | DigitalOut led1(LED1); //Setup the green LED. |
ziadeldebri | 3:b3b886fc6cf3 | 33 | AnalogIn ReadVoltage(A0); //Setup the analog input. |
star297 | 0:4f67859595b2 | 34 | |
star297 | 0:4f67859595b2 | 35 | |
star297 | 0:4f67859595b2 | 36 | main() |
star297 | 1:34f0bfc62803 | 37 | { |
ziadeldebri | 3:b3b886fc6cf3 | 38 | |
ziadeldebri | 3:b3b886fc6cf3 | 39 | //Add a pull up resistor to SW1. |
mattshuman | 2:eb8f263cccdb | 40 | led1 = 0; //Turn on the green LED. |
mattshuman | 2:eb8f263cccdb | 41 | slcd.DP1(1); //Turn on the decimal point |
star297 | 1:34f0bfc62803 | 42 | |
star297 | 1:34f0bfc62803 | 43 | while(1) { |
mattshuman | 2:eb8f263cccdb | 44 | led1=!led1; //Toggle the green LED |
mattshuman | 2:eb8f263cccdb | 45 | slcd.printf("%4.0f", ReadVoltage.read()*3300.f); //Use this line to read the analog input. |
ziadeldebri | 3:b3b886fc6cf3 | 46 | wait(2); //Wait 2 seconds. |
star297 | 0:4f67859595b2 | 47 | } |
star297 | 1:34f0bfc62803 | 48 | } |