This is an incomplete project for an in-class activity with a seven segment display.
main.cpp@1:fcc37968658c, 2016-10-18 (annotated)
- Committer:
- mattshuman
- Date:
- Tue Oct 18 22:49:24 2016 +0000
- Revision:
- 1:fcc37968658c
- Parent:
- 0:810603b26492
fixed demo
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 | 1:fcc37968658c | 34 | BusOut display(PTE31, PTE19, PTE18, PTE17, PTE16, PTE6, PTE3, PTE2); |
mattshuman | 1:fcc37968658c | 35 | //This creates an array of ports with PTE2 is the MSB and PTE31 is the LSB. |
mattshuman | 0:810603b26492 | 36 | |
mattshuman | 0:810603b26492 | 37 | main() |
mattshuman | 0:810603b26492 | 38 | { |
mattshuman | 0:810603b26492 | 39 | |
mattshuman | 0:810603b26492 | 40 | //Add a pull up resistor to SW1. |
mattshuman | 0:810603b26492 | 41 | led1 = 0; //Turn on the green LED. |
mattshuman | 0:810603b26492 | 42 | slcd.DP1(1); //Turn on the decimal point |
mattshuman | 0:810603b26492 | 43 | |
mattshuman | 0:810603b26492 | 44 | while(1) { |
mattshuman | 0:810603b26492 | 45 | led1=!led1; //Toggle the green LED |
mattshuman | 1:fcc37968658c | 46 | for(int i=0; i<16 ; i++){ |
mattshuman | 0:810603b26492 | 47 | slcd.printf(" %i",i); //Use this line to read the analog input. |
mattshuman | 0:810603b26492 | 48 | switch(i){ |
mattshuman | 1:fcc37968658c | 49 | case 0: display = 0x01;break; //also 0x01 //.abcedfg |
mattshuman | 1:fcc37968658c | 50 | case 1: display = 0xCF;break; |
mattshuman | 1:fcc37968658c | 51 | case 2: display = 0x92;break; |
mattshuman | 0:810603b26492 | 52 | case 3: display = 0x4F;break; |
mattshuman | 1:fcc37968658c | 53 | case 4: display = 0x66;break; |
mattshuman | 1:fcc37968658c | 54 | case 5: display = 0xA8;break; |
mattshuman | 1:fcc37968658c | 55 | case 6: display = 0x40;break; |
mattshuman | 1:fcc37968658c | 56 | case 7: display = 0x0F;break; |
mattshuman | 1:fcc37968658c | 57 | case 8: display = 0x80;break; |
mattshuman | 1:fcc37968658c | 58 | case 9: display = 0x77;break; |
mattshuman | 0:810603b26492 | 59 | }//end of switch |
mattshuman | 1:fcc37968658c | 60 | wait(2); |
mattshuman | 0:810603b26492 | 61 | }//end of for |
mattshuman | 0:810603b26492 | 62 | }//end of while |
mattshuman | 0:810603b26492 | 63 | }//end of main |