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
Diff: main.cpp
- Revision:
- 1:127190419363
- Parent:
- 0:93a3065ac203
- Child:
- 2:5f6ac2ea5870
--- a/main.cpp Fri Jan 22 17:59:50 2016 +0000 +++ b/main.cpp Fri Jan 22 19:55:41 2016 +0000 @@ -1,27 +1,20 @@ #include "mbed.h" +//#include "InterruptIn.h" +//#include "Serial.h" -void main() { -char Key; -Initialize(); -while(TRUE) { - Key=DisplayMenu(); - if(Key=='1') SimpleIO(); - else if(Key=='2') AnalogOutO(); - else if(Key=='3') AnalogIn(); - else if(Key=='4') PwmOut(); - else if(Key=='5') TimerIntInit(); - else if(Key=='6') ExternalIntInit(); - else if(Key=='7') LinearOpticalArrayTest(); - else if(Key=='8') BluetoothTest(); - else printf("\r\nInvalid keypress entry.\r\n"); - } -} +//Declarations +Serial pc(USBTX, USBRX); +//Digital Inputs +DigitalIn testIn(p25); +//Digital Outputs +DigitalOut testOut(LED1); + char DisplayMenu(void){ char Key; -disable_interrupts(INT_RTCC); -disable_interrupts(INT_EXT1); -disable_interrupts(GLOBAL) -printf("\n\r\n\r-----Robotics Test Program -----\n\n\r”); +//disable_interrupts(INT_RTCC); +//disable_interrupts(INT_EXT1); +//disable_interrupts(GLOBAL); +printf("\n\r\n\r-----Robotics Test Program -----\n\n\r"); printf("Type number followed by enter:"); printf("\n\r 1: Read digital value at XX and write to YY."); printf("\n\r 2: Write analog output at XX."); @@ -32,9 +25,114 @@ printf("\n\r 7: Linear optical array test."); printf("\n\r 8: Bluetooth communication.\n\r"); printf("Keypress = "); -Key=0x7F & getc(); +Key=0x7F & pc.getc(); printf("\n\r-------------------------------------"); printf("\r\nPressed Key = %C",Key); printf("\n\r-------------------------------------"); return(Key); } + +int SimpleIO(){ // read the state of a mechanical switch attached to a simple input port, display +//the logical value and then write the value to a simple output port that drives an LED. +if(testIn){ + printf("\r\n Logic Value = %f",testIn); +} +else{ + printf("\r\n Logic Value = %f",testIn); +} +testOut = testIn; +} + +int fAnalogOut(){// accept a value from the keyboard that is then written to the analog output pin +char Key; +//disable_interrupts(INT_RTCC); +//disable_interrupts(INT_EXT1); +//disable_interrupts(GLOBAL); +printf("Enter a value"); +printf("\n\rKeypress = "); +Key=0x7F & pc.getc(); +printf("\n\r-------------------------------------"); +printf("\r\nPressed Key = %C",Key); +printf("\n\r-------------------------------------"); +return(Key); + } + +int fAnalogIn(){//read the analog values at two analog input pins and display the converted +//values. Note: the A/D converter on the MBED processor is unipolar with a dynamic range of 0 to 3.3V. + } + +int fPWMOut(){ //generate a PWM output using one of the six PWM channels on the MBED. +//Assume the value of the period and the on-time is read from the keyboard + } + +int ExternalIntInit(){//initialize an external interrupt that causes an LED to toggle its state each +//time an external interrupt is detected. +} + +int TimerIntInit() +{ + + + } + +int LinearOpticalArrayTest(){//repeatedly generates scans of the TSL1401 with a fixed delay between scans +int i; +do { + //scan(ScanData); // Dummy scan + //wait_us(IntegrationTime); + //scan(ScanData); + if (pc.readable()){ + char x=pc.getc(); + if (x=='q') break; + else if (x=='i') + { + + + } + else if(x=='l') + { + //Display pixel values at the terminal + } + for(i=0; i<128; i=i+1) pc.printf("\n\n\r%d"/*, ScanData[i]*/); + } +}while(1); +pc.printf("\n\n\rTerminating clocking sequence for linear optical array.\n\r"); +} + +int BlueToothTest(){// The objective is to create the hardware and software interface illustrated +//in the figure below. Serial channel, Comm B, and the serial loopback path through the MBED +//processor will be used to initialize and configure the Parani/Promi Bluetooth module. Once +//configured, the objective is to enter keystrokes at Terminal A and have them displayed at Terminal +//B; and to have keystrokes entered at Terminal A displayed at Terminal B. + + +} + +void scan(short ScanData[]) { +int j; + //LoaSI=1; + //LoaCLK=1; + //LoaSI=0; + for(j=0;j<128;j=j+1){ + //ScanData[j]=LoaAnalogIn.read_u16(); + //LoaCLK=0; //delay_us(1); + //LoaCLK=1; + } + //LoaCLK=0; +} + +void main() { +char Key; +//Initialize(); +//while(TRUE) { + Key=DisplayMenu(); + if(Key=='1') SimpleIO(); //LAB 2.2 + else if(Key=='2') fAnalogOut(); //LAB 2.3 + else if(Key=='3') fAnalogIn(); //LAB 2.4 + else if(Key=='4') fPWMOut(); //LAB 2.5 + else if(Key=='5') TimerIntInit(); //LAB 2.6 + else if(Key=='6') ExternalIntInit(); //LAB 2.7 + else if(Key=='7') LinearOpticalArrayTest(); //LAB 2.8 + else if(Key=='8') BlueToothTest(); //LAB 2.9 + else printf("\r\nInvalid keypress entry.\r\n"); +}