Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@6:2db8f8299773, 2016-01-28 (annotated)
- Committer:
- A_Sterner
- Date:
- Thu Jan 28 18:24:39 2016 +0000
- Revision:
- 6:2db8f8299773
- Parent:
- 5:6f51a96a5094
- Child:
- 7:3ad02c0c93a9
Some minor changes - WE NEED TO USE GETS, NOT GETC, TO GET MULTIPLE CHARACTERS!!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JordanWisdom | 0:93a3065ac203 | 1 | #include "mbed.h" |
JordanWisdom | 1:127190419363 | 2 | //#include "InterruptIn.h" |
JordanWisdom | 1:127190419363 | 3 | //#include "Serial.h" |
JordanWisdom | 0:93a3065ac203 | 4 | |
JordanWisdom | 2:5f6ac2ea5870 | 5 | //DECLARATIONS |
JordanWisdom | 1:127190419363 | 6 | Serial pc(USBTX, USBRX); |
A_Sterner | 5:6f51a96a5094 | 7 | |
JordanWisdom | 1:127190419363 | 8 | //Digital Inputs |
A_Sterner | 5:6f51a96a5094 | 9 | DigitalIn Sw1(p24); |
A_Sterner | 5:6f51a96a5094 | 10 | |
JordanWisdom | 1:127190419363 | 11 | //Digital Outputs |
A_Sterner | 5:6f51a96a5094 | 12 | DigitalOut DOut1(p25); |
A_Sterner | 5:6f51a96a5094 | 13 | |
JordanWisdom | 2:5f6ac2ea5870 | 14 | //Analog Inputs |
A_Sterner | 5:6f51a96a5094 | 15 | AnalogIn AnaInput1(p15); |
A_Sterner | 5:6f51a96a5094 | 16 | AnalogIn AnaInput2(p16); |
A_Sterner | 5:6f51a96a5094 | 17 | |
JordanWisdom | 2:5f6ac2ea5870 | 18 | //Analog Outputs |
A_Sterner | 5:6f51a96a5094 | 19 | AnalogOut AOutput(p18); |
A_Sterner | 5:6f51a96a5094 | 20 | |
JordanWisdom | 4:535e67099871 | 21 | //PWM Outs |
A_Sterner | 5:6f51a96a5094 | 22 | PwmOut PWM(p21); |
JordanWisdom | 1:127190419363 | 23 | |
JordanWisdom | 0:93a3065ac203 | 24 | char DisplayMenu(void){ |
JordanWisdom | 0:93a3065ac203 | 25 | char Key; |
A_Sterner | 5:6f51a96a5094 | 26 | printf("\n\r-----Robotics Test Program -----\n"); |
A_Sterner | 5:6f51a96a5094 | 27 | printf("\n\r Type number followed by enter:"); |
A_Sterner | 5:6f51a96a5094 | 28 | printf("\n\r 1: Read digital value at XX and write to YY."); |
A_Sterner | 5:6f51a96a5094 | 29 | printf("\n\r 2: Write analog output at XX."); |
A_Sterner | 5:6f51a96a5094 | 30 | printf("\n\r 3: Read analog input at YY and ZZ."); |
A_Sterner | 5:6f51a96a5094 | 31 | printf("\n\r 4: PWM output at XX."); |
A_Sterner | 5:6f51a96a5094 | 32 | printf("\n\r 5: Timer interrupt generation."); |
A_Sterner | 5:6f51a96a5094 | 33 | printf("\n\r 6: External interrupt generation."); |
A_Sterner | 5:6f51a96a5094 | 34 | printf("\n\r 7: Linear optical array test."); |
A_Sterner | 5:6f51a96a5094 | 35 | printf("\n\r 8: Bluetooth communication."); |
A_Sterner | 6:2db8f8299773 | 36 | printf("\n\r Keypress = "); |
A_Sterner | 5:6f51a96a5094 | 37 | Key=0x7F & pc.getc(); |
A_Sterner | 6:2db8f8299773 | 38 | wait_ms(100); |
A_Sterner | 5:6f51a96a5094 | 39 | printf("\n\r-------------------------------------"); |
A_Sterner | 5:6f51a96a5094 | 40 | printf("\r\n Pressed Key = %C",Key); |
A_Sterner | 5:6f51a96a5094 | 41 | printf("\n\r-------------------------------------"); |
A_Sterner | 5:6f51a96a5094 | 42 | return(Key); |
JordanWisdom | 0:93a3065ac203 | 43 | } |
JordanWisdom | 1:127190419363 | 44 | |
A_Sterner | 5:6f51a96a5094 | 45 | int SimpleIO(){ |
A_Sterner | 5:6f51a96a5094 | 46 | bool z; |
A_Sterner | 5:6f51a96a5094 | 47 | z = Sw1; |
A_Sterner | 5:6f51a96a5094 | 48 | DOut1 = z; |
A_Sterner | 5:6f51a96a5094 | 49 | printf("\r\n Logic Value = %x",z); |
A_Sterner | 5:6f51a96a5094 | 50 | DOut1 = Sw1; |
JordanWisdom | 1:127190419363 | 51 | } |
JordanWisdom | 1:127190419363 | 52 | |
A_Sterner | 5:6f51a96a5094 | 53 | int AOut(){ |
A_Sterner | 5:6f51a96a5094 | 54 | char Key; |
A_Sterner | 5:6f51a96a5094 | 55 | printf("\n\rEnter a value"); |
A_Sterner | 5:6f51a96a5094 | 56 | printf("\n\r Keypress = "); |
A_Sterner | 5:6f51a96a5094 | 57 | Key=0x7F & pc.getc(); |
A_Sterner | 5:6f51a96a5094 | 58 | printf("\n\r-------------------------------------"); |
A_Sterner | 6:2db8f8299773 | 59 | printf("\r\n Pressed Key = %s",Key); |
A_Sterner | 5:6f51a96a5094 | 60 | printf("\n\r-------------------------------------"); |
A_Sterner | 5:6f51a96a5094 | 61 | AOutput.write(Key); |
A_Sterner | 5:6f51a96a5094 | 62 | } |
JordanWisdom | 1:127190419363 | 63 | |
A_Sterner | 5:6f51a96a5094 | 64 | int fAnalogIn(){ |
A_Sterner | 5:6f51a96a5094 | 65 | AOutput.write(AnaInput1.read()); |
A_Sterner | 5:6f51a96a5094 | 66 | printf("\n\r Analog Output = %1.4f volts\n", AnaInput1.read() * 3.3f); |
A_Sterner | 5:6f51a96a5094 | 67 | printf("\n\r Analog Input = %1.4f volts\n", AnaInput2.read() * 3.3f); |
A_Sterner | 5:6f51a96a5094 | 68 | } |
JordanWisdom | 1:127190419363 | 69 | |
A_Sterner | 5:6f51a96a5094 | 70 | int PWMOut(){ |
A_Sterner | 5:6f51a96a5094 | 71 | |
A_Sterner | 5:6f51a96a5094 | 72 | //Specify Period First |
A_Sterner | 5:6f51a96a5094 | 73 | float T; |
A_Sterner | 5:6f51a96a5094 | 74 | float PW; |
A_Sterner | 6:2db8f8299773 | 75 | printf("\n\r\n\r-----Robotics PWM Options-----"); |
A_Sterner | 6:2db8f8299773 | 76 | printf("\n\rEnter a Period in Seconds:"); |
A_Sterner | 6:2db8f8299773 | 77 | pc.scanf("%f",&T); |
A_Sterner | 5:6f51a96a5094 | 78 | PWM.period(T); |
A_Sterner | 6:2db8f8299773 | 79 | wait_ms(100); |
A_Sterner | 6:2db8f8299773 | 80 | printf("\n\rEnter a Pulse Width in Seconds:"); |
A_Sterner | 6:2db8f8299773 | 81 | pc.scanf("%f",&PW); |
A_Sterner | 5:6f51a96a5094 | 82 | PWM.pulsewidth(PW); |
A_Sterner | 6:2db8f8299773 | 83 | wait_ms(100); |
A_Sterner | 6:2db8f8299773 | 84 | printf("\n\rPeriod in Seconds: %f", T); |
A_Sterner | 6:2db8f8299773 | 85 | printf("\n\rPulse Width in Seconds: %f", PW); |
A_Sterner | 6:2db8f8299773 | 86 | |
A_Sterner | 6:2db8f8299773 | 87 | |
A_Sterner | 6:2db8f8299773 | 88 | |
A_Sterner | 5:6f51a96a5094 | 89 | } |
JordanWisdom | 1:127190419363 | 90 | |
JordanWisdom | 1:127190419363 | 91 | int ExternalIntInit(){//initialize an external interrupt that causes an LED to toggle its state each |
JordanWisdom | 1:127190419363 | 92 | //time an external interrupt is detected. |
JordanWisdom | 1:127190419363 | 93 | } |
JordanWisdom | 1:127190419363 | 94 | |
JordanWisdom | 1:127190419363 | 95 | int TimerIntInit() |
JordanWisdom | 1:127190419363 | 96 | { |
JordanWisdom | 1:127190419363 | 97 | |
JordanWisdom | 1:127190419363 | 98 | |
JordanWisdom | 1:127190419363 | 99 | } |
JordanWisdom | 1:127190419363 | 100 | |
JordanWisdom | 1:127190419363 | 101 | int LinearOpticalArrayTest(){//repeatedly generates scans of the TSL1401 with a fixed delay between scans |
JordanWisdom | 1:127190419363 | 102 | int i; |
JordanWisdom | 1:127190419363 | 103 | do { |
JordanWisdom | 1:127190419363 | 104 | //scan(ScanData); // Dummy scan |
JordanWisdom | 1:127190419363 | 105 | //wait_us(IntegrationTime); |
JordanWisdom | 1:127190419363 | 106 | //scan(ScanData); |
JordanWisdom | 1:127190419363 | 107 | if (pc.readable()){ |
JordanWisdom | 1:127190419363 | 108 | char x=pc.getc(); |
JordanWisdom | 1:127190419363 | 109 | if (x=='q') break; |
JordanWisdom | 1:127190419363 | 110 | else if (x=='i') |
JordanWisdom | 1:127190419363 | 111 | { |
JordanWisdom | 1:127190419363 | 112 | |
JordanWisdom | 1:127190419363 | 113 | |
JordanWisdom | 1:127190419363 | 114 | } |
JordanWisdom | 1:127190419363 | 115 | else if(x=='l') |
JordanWisdom | 1:127190419363 | 116 | { |
JordanWisdom | 1:127190419363 | 117 | //Display pixel values at the terminal |
JordanWisdom | 1:127190419363 | 118 | } |
JordanWisdom | 1:127190419363 | 119 | for(i=0; i<128; i=i+1) pc.printf("\n\n\r%d"/*, ScanData[i]*/); |
JordanWisdom | 1:127190419363 | 120 | } |
JordanWisdom | 1:127190419363 | 121 | }while(1); |
JordanWisdom | 1:127190419363 | 122 | pc.printf("\n\n\rTerminating clocking sequence for linear optical array.\n\r"); |
JordanWisdom | 1:127190419363 | 123 | } |
JordanWisdom | 1:127190419363 | 124 | |
JordanWisdom | 1:127190419363 | 125 | int BlueToothTest(){// The objective is to create the hardware and software interface illustrated |
JordanWisdom | 1:127190419363 | 126 | //in the figure below. Serial channel, Comm B, and the serial loopback path through the MBED |
JordanWisdom | 1:127190419363 | 127 | //processor will be used to initialize and configure the Parani/Promi Bluetooth module. Once |
JordanWisdom | 1:127190419363 | 128 | //configured, the objective is to enter keystrokes at Terminal A and have them displayed at Terminal |
JordanWisdom | 1:127190419363 | 129 | //B; and to have keystrokes entered at Terminal A displayed at Terminal B. |
JordanWisdom | 1:127190419363 | 130 | |
JordanWisdom | 1:127190419363 | 131 | |
JordanWisdom | 1:127190419363 | 132 | } |
JordanWisdom | 1:127190419363 | 133 | |
JordanWisdom | 1:127190419363 | 134 | void scan(short ScanData[]) { |
JordanWisdom | 1:127190419363 | 135 | int j; |
JordanWisdom | 1:127190419363 | 136 | //LoaSI=1; |
JordanWisdom | 1:127190419363 | 137 | //LoaCLK=1; |
JordanWisdom | 1:127190419363 | 138 | //LoaSI=0; |
JordanWisdom | 1:127190419363 | 139 | for(j=0;j<128;j=j+1){ |
JordanWisdom | 1:127190419363 | 140 | //ScanData[j]=LoaAnalogIn.read_u16(); |
JordanWisdom | 1:127190419363 | 141 | //LoaCLK=0; //delay_us(1); |
JordanWisdom | 1:127190419363 | 142 | //LoaCLK=1; |
JordanWisdom | 1:127190419363 | 143 | } |
JordanWisdom | 1:127190419363 | 144 | //LoaCLK=0; |
JordanWisdom | 1:127190419363 | 145 | } |
JordanWisdom | 1:127190419363 | 146 | |
A_Sterner | 5:6f51a96a5094 | 147 | void main(void) { |
JordanWisdom | 1:127190419363 | 148 | char Key; |
JordanWisdom | 1:127190419363 | 149 | //Initialize(); |
A_Sterner | 5:6f51a96a5094 | 150 | while(1) { |
JordanWisdom | 1:127190419363 | 151 | Key=DisplayMenu(); |
JordanWisdom | 1:127190419363 | 152 | if(Key=='1') SimpleIO(); //LAB 2.2 |
A_Sterner | 6:2db8f8299773 | 153 | else if(Key=='2') AOut(); //LAB 2.3 |
JordanWisdom | 4:535e67099871 | 154 | else if(Key=='3') fAnalogIn(); //LAB 2.4 |
A_Sterner | 5:6f51a96a5094 | 155 | else if(Key=='4') PWMOut(); //LAB 2.5 |
JordanWisdom | 1:127190419363 | 156 | else if(Key=='5') TimerIntInit(); //LAB 2.6 |
JordanWisdom | 1:127190419363 | 157 | else if(Key=='6') ExternalIntInit(); //LAB 2.7 |
JordanWisdom | 1:127190419363 | 158 | else if(Key=='7') LinearOpticalArrayTest(); //LAB 2.8 |
JordanWisdom | 1:127190419363 | 159 | else if(Key=='8') BlueToothTest(); //LAB 2.9 |
JordanWisdom | 1:127190419363 | 160 | else printf("\r\nInvalid keypress entry.\r\n"); |
JordanWisdom | 1:127190419363 | 161 | } |
A_Sterner | 5:6f51a96a5094 | 162 | } |