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@1:127190419363, 2016-01-22 (annotated)
- Committer:
- JordanWisdom
- Date:
- Fri Jan 22 19:55:41 2016 +0000
- Revision:
- 1:127190419363
- Parent:
- 0:93a3065ac203
- Child:
- 2:5f6ac2ea5870
First Draft of Lab 2
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 | 1:127190419363 | 5 | //Declarations |
JordanWisdom | 1:127190419363 | 6 | Serial pc(USBTX, USBRX); |
JordanWisdom | 1:127190419363 | 7 | //Digital Inputs |
JordanWisdom | 1:127190419363 | 8 | DigitalIn testIn(p25); |
JordanWisdom | 1:127190419363 | 9 | //Digital Outputs |
JordanWisdom | 1:127190419363 | 10 | DigitalOut testOut(LED1); |
JordanWisdom | 1:127190419363 | 11 | |
JordanWisdom | 0:93a3065ac203 | 12 | char DisplayMenu(void){ |
JordanWisdom | 0:93a3065ac203 | 13 | char Key; |
JordanWisdom | 1:127190419363 | 14 | //disable_interrupts(INT_RTCC); |
JordanWisdom | 1:127190419363 | 15 | //disable_interrupts(INT_EXT1); |
JordanWisdom | 1:127190419363 | 16 | //disable_interrupts(GLOBAL); |
JordanWisdom | 1:127190419363 | 17 | printf("\n\r\n\r-----Robotics Test Program -----\n\n\r"); |
JordanWisdom | 0:93a3065ac203 | 18 | printf("Type number followed by enter:"); |
JordanWisdom | 0:93a3065ac203 | 19 | printf("\n\r 1: Read digital value at XX and write to YY."); |
JordanWisdom | 0:93a3065ac203 | 20 | printf("\n\r 2: Write analog output at XX."); |
JordanWisdom | 0:93a3065ac203 | 21 | printf("\n\r 3: Read analog input at YY and ZZ."); |
JordanWisdom | 0:93a3065ac203 | 22 | printf("\n\r 4: PWM output at XX."); |
JordanWisdom | 0:93a3065ac203 | 23 | printf("\n\r 5: Timer interrupt generation."); |
JordanWisdom | 0:93a3065ac203 | 24 | printf("\n\r 6: External interrupt generation."); |
JordanWisdom | 0:93a3065ac203 | 25 | printf("\n\r 7: Linear optical array test."); |
JordanWisdom | 0:93a3065ac203 | 26 | printf("\n\r 8: Bluetooth communication.\n\r"); |
JordanWisdom | 0:93a3065ac203 | 27 | printf("Keypress = "); |
JordanWisdom | 1:127190419363 | 28 | Key=0x7F & pc.getc(); |
JordanWisdom | 0:93a3065ac203 | 29 | printf("\n\r-------------------------------------"); |
JordanWisdom | 0:93a3065ac203 | 30 | printf("\r\nPressed Key = %C",Key); |
JordanWisdom | 0:93a3065ac203 | 31 | printf("\n\r-------------------------------------"); |
JordanWisdom | 0:93a3065ac203 | 32 | return(Key); |
JordanWisdom | 0:93a3065ac203 | 33 | } |
JordanWisdom | 1:127190419363 | 34 | |
JordanWisdom | 1:127190419363 | 35 | int SimpleIO(){ // read the state of a mechanical switch attached to a simple input port, display |
JordanWisdom | 1:127190419363 | 36 | //the logical value and then write the value to a simple output port that drives an LED. |
JordanWisdom | 1:127190419363 | 37 | if(testIn){ |
JordanWisdom | 1:127190419363 | 38 | printf("\r\n Logic Value = %f",testIn); |
JordanWisdom | 1:127190419363 | 39 | } |
JordanWisdom | 1:127190419363 | 40 | else{ |
JordanWisdom | 1:127190419363 | 41 | printf("\r\n Logic Value = %f",testIn); |
JordanWisdom | 1:127190419363 | 42 | } |
JordanWisdom | 1:127190419363 | 43 | testOut = testIn; |
JordanWisdom | 1:127190419363 | 44 | } |
JordanWisdom | 1:127190419363 | 45 | |
JordanWisdom | 1:127190419363 | 46 | int fAnalogOut(){// accept a value from the keyboard that is then written to the analog output pin |
JordanWisdom | 1:127190419363 | 47 | char Key; |
JordanWisdom | 1:127190419363 | 48 | //disable_interrupts(INT_RTCC); |
JordanWisdom | 1:127190419363 | 49 | //disable_interrupts(INT_EXT1); |
JordanWisdom | 1:127190419363 | 50 | //disable_interrupts(GLOBAL); |
JordanWisdom | 1:127190419363 | 51 | printf("Enter a value"); |
JordanWisdom | 1:127190419363 | 52 | printf("\n\rKeypress = "); |
JordanWisdom | 1:127190419363 | 53 | Key=0x7F & pc.getc(); |
JordanWisdom | 1:127190419363 | 54 | printf("\n\r-------------------------------------"); |
JordanWisdom | 1:127190419363 | 55 | printf("\r\nPressed Key = %C",Key); |
JordanWisdom | 1:127190419363 | 56 | printf("\n\r-------------------------------------"); |
JordanWisdom | 1:127190419363 | 57 | return(Key); |
JordanWisdom | 1:127190419363 | 58 | } |
JordanWisdom | 1:127190419363 | 59 | |
JordanWisdom | 1:127190419363 | 60 | int fAnalogIn(){//read the analog values at two analog input pins and display the converted |
JordanWisdom | 1:127190419363 | 61 | //values. Note: the A/D converter on the MBED processor is unipolar with a dynamic range of 0 to 3.3V. |
JordanWisdom | 1:127190419363 | 62 | } |
JordanWisdom | 1:127190419363 | 63 | |
JordanWisdom | 1:127190419363 | 64 | int fPWMOut(){ //generate a PWM output using one of the six PWM channels on the MBED. |
JordanWisdom | 1:127190419363 | 65 | //Assume the value of the period and the on-time is read from the keyboard |
JordanWisdom | 1:127190419363 | 66 | } |
JordanWisdom | 1:127190419363 | 67 | |
JordanWisdom | 1:127190419363 | 68 | int ExternalIntInit(){//initialize an external interrupt that causes an LED to toggle its state each |
JordanWisdom | 1:127190419363 | 69 | //time an external interrupt is detected. |
JordanWisdom | 1:127190419363 | 70 | } |
JordanWisdom | 1:127190419363 | 71 | |
JordanWisdom | 1:127190419363 | 72 | int TimerIntInit() |
JordanWisdom | 1:127190419363 | 73 | { |
JordanWisdom | 1:127190419363 | 74 | |
JordanWisdom | 1:127190419363 | 75 | |
JordanWisdom | 1:127190419363 | 76 | } |
JordanWisdom | 1:127190419363 | 77 | |
JordanWisdom | 1:127190419363 | 78 | int LinearOpticalArrayTest(){//repeatedly generates scans of the TSL1401 with a fixed delay between scans |
JordanWisdom | 1:127190419363 | 79 | int i; |
JordanWisdom | 1:127190419363 | 80 | do { |
JordanWisdom | 1:127190419363 | 81 | //scan(ScanData); // Dummy scan |
JordanWisdom | 1:127190419363 | 82 | //wait_us(IntegrationTime); |
JordanWisdom | 1:127190419363 | 83 | //scan(ScanData); |
JordanWisdom | 1:127190419363 | 84 | if (pc.readable()){ |
JordanWisdom | 1:127190419363 | 85 | char x=pc.getc(); |
JordanWisdom | 1:127190419363 | 86 | if (x=='q') break; |
JordanWisdom | 1:127190419363 | 87 | else if (x=='i') |
JordanWisdom | 1:127190419363 | 88 | { |
JordanWisdom | 1:127190419363 | 89 | |
JordanWisdom | 1:127190419363 | 90 | |
JordanWisdom | 1:127190419363 | 91 | } |
JordanWisdom | 1:127190419363 | 92 | else if(x=='l') |
JordanWisdom | 1:127190419363 | 93 | { |
JordanWisdom | 1:127190419363 | 94 | //Display pixel values at the terminal |
JordanWisdom | 1:127190419363 | 95 | } |
JordanWisdom | 1:127190419363 | 96 | for(i=0; i<128; i=i+1) pc.printf("\n\n\r%d"/*, ScanData[i]*/); |
JordanWisdom | 1:127190419363 | 97 | } |
JordanWisdom | 1:127190419363 | 98 | }while(1); |
JordanWisdom | 1:127190419363 | 99 | pc.printf("\n\n\rTerminating clocking sequence for linear optical array.\n\r"); |
JordanWisdom | 1:127190419363 | 100 | } |
JordanWisdom | 1:127190419363 | 101 | |
JordanWisdom | 1:127190419363 | 102 | int BlueToothTest(){// The objective is to create the hardware and software interface illustrated |
JordanWisdom | 1:127190419363 | 103 | //in the figure below. Serial channel, Comm B, and the serial loopback path through the MBED |
JordanWisdom | 1:127190419363 | 104 | //processor will be used to initialize and configure the Parani/Promi Bluetooth module. Once |
JordanWisdom | 1:127190419363 | 105 | //configured, the objective is to enter keystrokes at Terminal A and have them displayed at Terminal |
JordanWisdom | 1:127190419363 | 106 | //B; and to have keystrokes entered at Terminal A displayed at Terminal B. |
JordanWisdom | 1:127190419363 | 107 | |
JordanWisdom | 1:127190419363 | 108 | |
JordanWisdom | 1:127190419363 | 109 | } |
JordanWisdom | 1:127190419363 | 110 | |
JordanWisdom | 1:127190419363 | 111 | void scan(short ScanData[]) { |
JordanWisdom | 1:127190419363 | 112 | int j; |
JordanWisdom | 1:127190419363 | 113 | //LoaSI=1; |
JordanWisdom | 1:127190419363 | 114 | //LoaCLK=1; |
JordanWisdom | 1:127190419363 | 115 | //LoaSI=0; |
JordanWisdom | 1:127190419363 | 116 | for(j=0;j<128;j=j+1){ |
JordanWisdom | 1:127190419363 | 117 | //ScanData[j]=LoaAnalogIn.read_u16(); |
JordanWisdom | 1:127190419363 | 118 | //LoaCLK=0; //delay_us(1); |
JordanWisdom | 1:127190419363 | 119 | //LoaCLK=1; |
JordanWisdom | 1:127190419363 | 120 | } |
JordanWisdom | 1:127190419363 | 121 | //LoaCLK=0; |
JordanWisdom | 1:127190419363 | 122 | } |
JordanWisdom | 1:127190419363 | 123 | |
JordanWisdom | 1:127190419363 | 124 | void main() { |
JordanWisdom | 1:127190419363 | 125 | char Key; |
JordanWisdom | 1:127190419363 | 126 | //Initialize(); |
JordanWisdom | 1:127190419363 | 127 | //while(TRUE) { |
JordanWisdom | 1:127190419363 | 128 | Key=DisplayMenu(); |
JordanWisdom | 1:127190419363 | 129 | if(Key=='1') SimpleIO(); //LAB 2.2 |
JordanWisdom | 1:127190419363 | 130 | else if(Key=='2') fAnalogOut(); //LAB 2.3 |
JordanWisdom | 1:127190419363 | 131 | else if(Key=='3') fAnalogIn(); //LAB 2.4 |
JordanWisdom | 1:127190419363 | 132 | else if(Key=='4') fPWMOut(); //LAB 2.5 |
JordanWisdom | 1:127190419363 | 133 | else if(Key=='5') TimerIntInit(); //LAB 2.6 |
JordanWisdom | 1:127190419363 | 134 | else if(Key=='6') ExternalIntInit(); //LAB 2.7 |
JordanWisdom | 1:127190419363 | 135 | else if(Key=='7') LinearOpticalArrayTest(); //LAB 2.8 |
JordanWisdom | 1:127190419363 | 136 | else if(Key=='8') BlueToothTest(); //LAB 2.9 |
JordanWisdom | 1:127190419363 | 137 | else printf("\r\nInvalid keypress entry.\r\n"); |
JordanWisdom | 1:127190419363 | 138 | } |