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
- Committer:
- A_Sterner
- Date:
- 2016-01-28
- Revision:
- 5:6f51a96a5094
- Parent:
- 4:535e67099871
- Child:
- 6:2db8f8299773
File content as of revision 5:6f51a96a5094:
#include "mbed.h" //#include "InterruptIn.h" //#include "Serial.h" //DECLARATIONS Serial pc(USBTX, USBRX); //Digital Inputs DigitalIn Sw1(p24); //Digital Outputs DigitalOut DOut1(p25); //Analog Inputs AnalogIn AnaInput1(p15); AnalogIn AnaInput2(p16); //Analog Outputs AnalogOut AOutput(p18); //PWM Outs PwmOut PWM(p21); char DisplayMenu(void){ char Key; printf("\n\r-----Robotics Test Program -----\n"); printf("\n\r 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."); printf("\n\r 3: Read analog input at YY and ZZ."); printf("\n\r 4: PWM output at XX."); printf("\n\r 5: Timer interrupt generation."); printf("\n\r 6: External interrupt generation."); printf("\n\r 7: Linear optical array test."); printf("\n\r 8: Bluetooth communication."); printf("\n\r Keypress = "); Key=0x7F & pc.getc(); printf("\n\r-------------------------------------"); printf("\r\n Pressed Key = %C",Key); printf("\n\r-------------------------------------"); return(Key); } int SimpleIO(){ bool z; z = Sw1; DOut1 = z; printf("\r\n Logic Value = %x",z); DOut1 = Sw1; } int AOut(){ char Key; printf("\n\rEnter a value"); printf("\n\r Keypress = "); Key=0x7F & pc.getc(); printf("\n\r-------------------------------------"); printf("\r\n Pressed Key = %C",Key); printf("\n\r-------------------------------------"); AOutput.write(Key); } int fAnalogIn(){ AOutput.write(AnaInput1.read()); printf("\n\r Analog Output = %1.4f volts\n", AnaInput1.read() * 3.3f); printf("\n\r Analog Input = %1.4f volts\n", AnaInput2.read() * 3.3f); } int PWMOut(){ //Specify Period First float T; float PW; printf("\n\r\n\r-----Robotics PWM Options-----\n\n\r"); printf("Type the period in seconds:"); printf("\n\rKeypress = "); T =0x7F & pc.getc(); PWM.period(T); printf("\n\r Enter the pulse width in milliseconds."); PW=0x7F & pc.getc(); PWM.pulsewidth(PW); } 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(void) { char Key; //Initialize(); while(1) { Key=DisplayMenu(); if(Key=='1') SimpleIO(); //LAB 2.2 else if(Key=='2') AOut(); //LAB 2.3 else if(Key=='3') fAnalogIn(); //LAB 2.4 else if(Key=='4') PWMOut(); //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"); } }