This is an incomplete project for an in-class activity with a seven segment display.
main.cpp@0:810603b26492, 2016-10-18 (annotated)
- Committer:
- mattshuman
- Date:
- Tue Oct 18 16:36:06 2016 +0000
- Revision:
- 0:810603b26492
- Child:
- 1:fcc37968658c
This is an incomplete project, designed for an in-class activity with seven-segment displays.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mattshuman | 0:810603b26492 | 1 | /*! Lab2 |
mattshuman | 0:810603b26492 | 2 | * Used to turn the FRDM-KL46Z into a voltmeter. |
mattshuman | 0:810603b26492 | 3 | * Modified from: https://developer.mbed.org/users/star297/code/FRDM-KL46Z-LCD-rtc-Demo/ |
mattshuman | 0:810603b26492 | 4 | * \author Matthew Shuman |
mattshuman | 0:810603b26492 | 5 | * |
mattshuman | 0:810603b26492 | 6 | * \date August 28th, 2016 |
mattshuman | 0:810603b26492 | 7 | |
mattshuman | 0:810603b26492 | 8 | * \bug No bugs yet |
mattshuman | 0:810603b26492 | 9 | |
mattshuman | 0:810603b26492 | 10 | * @code |
mattshuman | 0:810603b26492 | 11 | * #include "mbed.h" |
mattshuman | 0:810603b26492 | 12 | * #include "SLCD.h" |
mattshuman | 0:810603b26492 | 13 | |
mattshuman | 0:810603b26492 | 14 | * SLCD myLcd; |
mattshuman | 0:810603b26492 | 15 | * int myNumber=0; |
mattshuman | 0:810603b26492 | 16 | * int main() |
mattshuman | 0:810603b26492 | 17 | * { |
mattshuman | 0:810603b26492 | 18 | * while(1) { |
mattshuman | 0:810603b26492 | 19 | * myLcd.printf("00%2.0i",myNumber); |
mattshuman | 0:810603b26492 | 20 | * ++myNumber; |
mattshuman | 0:810603b26492 | 21 | * wait(.1); |
mattshuman | 0:810603b26492 | 22 | * }//end of while |
mattshuman | 0:810603b26492 | 23 | * }//end of main |
mattshuman | 0:810603b26492 | 24 | * @endcode |
mattshuman | 0:810603b26492 | 25 | */ |
mattshuman | 0:810603b26492 | 26 | |
mattshuman | 0:810603b26492 | 27 | |
mattshuman | 0:810603b26492 | 28 | #include "mbed.h" |
mattshuman | 0:810603b26492 | 29 | #include "SLCD.h" |
mattshuman | 0:810603b26492 | 30 | |
mattshuman | 0:810603b26492 | 31 | SLCD slcd; //Setup the LCD on the FRDM-KL46Z. |
mattshuman | 0:810603b26492 | 32 | DigitalOut led1(LED1); //Setup the green LED. |
mattshuman | 0:810603b26492 | 33 | AnalogIn ReadVoltage(A0); //Setup the analog input. |
mattshuman | 0:810603b26492 | 34 | BusOut display(PTE31, PTE19, PTE18, PTE17, PTE16, PTE6, PTE3); |
mattshuman | 0:810603b26492 | 35 | |
mattshuman | 0:810603b26492 | 36 | main() |
mattshuman | 0:810603b26492 | 37 | { |
mattshuman | 0:810603b26492 | 38 | |
mattshuman | 0:810603b26492 | 39 | //Add a pull up resistor to SW1. |
mattshuman | 0:810603b26492 | 40 | led1 = 0; //Turn on the green LED. |
mattshuman | 0:810603b26492 | 41 | slcd.DP1(1); //Turn on the decimal point |
mattshuman | 0:810603b26492 | 42 | |
mattshuman | 0:810603b26492 | 43 | while(1) { |
mattshuman | 0:810603b26492 | 44 | led1=!led1; //Toggle the green LED |
mattshuman | 0:810603b26492 | 45 | for(int i=0; i<4 ; i++){ |
mattshuman | 0:810603b26492 | 46 | slcd.printf(" %i",i); //Use this line to read the analog input. |
mattshuman | 0:810603b26492 | 47 | switch(i){ |
mattshuman | 0:810603b26492 | 48 | case 0: display = 0x3F;break; |
mattshuman | 0:810603b26492 | 49 | case 1: display = 0x06;break; |
mattshuman | 0:810603b26492 | 50 | case 2: display = 0x5B;break; |
mattshuman | 0:810603b26492 | 51 | case 3: display = 0x4F;break; |
mattshuman | 0:810603b26492 | 52 | }//end of switch |
mattshuman | 0:810603b26492 | 53 | wait(1); |
mattshuman | 0:810603b26492 | 54 | }//end of for |
mattshuman | 0:810603b26492 | 55 | }//end of while |
mattshuman | 0:810603b26492 | 56 | }//end of main |