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:
- 5:6f51a96a5094
- Parent:
- 4:535e67099871
- Child:
- 6:2db8f8299773
--- a/main.cpp Fri Jan 22 20:20:20 2016 +0000 +++ b/main.cpp Thu Jan 28 17:45:01 2016 +0000 @@ -4,87 +4,83 @@ //DECLARATIONS Serial pc(USBTX, USBRX); + //Digital Inputs -DigitalIn testIn(p24); +DigitalIn Sw1(p24); + //Digital Outputs -DigitalOut testOut(p25); +DigitalOut DOut1(p25); + //Analog Inputs -AnalogIn AIn(p26); +AnalogIn AnaInput1(p15); +AnalogIn AnaInput2(p16); + //Analog Outputs -AnalogOut AOut(p27); -AnalogOut BOut(p28); +AnalogOut AOutput(p18); + //PWM Outs -PWMOut pulse(p21); - +PwmOut PWM(p21); 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"); -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."); -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.\n\r"); -printf("Keypress = "); -Key=0x7F & pc.getc(); -printf("\n\r-------------------------------------"); -printf("\r\nPressed Key = %C",Key); -printf("\n\r-------------------------------------"); -return(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(){ // 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 SimpleIO(){ + bool z; + z = Sw1; + DOut1 = z; + printf("\r\n Logic Value = %x",z); + DOut1 = Sw1; } -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-------------------------------------"); -AOut.write(Key); - } +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(){//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 AInCheck = AIn.read(); -AOut.write(AInCheck); -BOut.write(AInCheck); - } +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 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 -//Specify Period First -int Key -printf("\n\r\n\r-----Robotics PWM Options-----\n\n\r"); -printf("Type the period in seconds:"); -printf("\n\rKeypress = "); -Key = pc.getc(); -pulse.period(Key); -printf("\n\r Enter the pulse width in seconds."); -Key = pc.getc(); -pulse.pulsewidth(Key); - } +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. @@ -142,18 +138,19 @@ //LoaCLK=0; } -void main() { +void main(void) { char Key; //Initialize(); -//while(TRUE) { +while(1) { Key=DisplayMenu(); if(Key=='1') SimpleIO(); //LAB 2.2 - else if(Key=='2') fAnalogOut(); //LAB 2.3 +else if(Key=='2') AOut(); //LAB 2.3 else if(Key=='3') fAnalogIn(); //LAB 2.4 - else if(Key=='4') fPWMOut(); //LAB 2.5 + 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"); } +}