Lab 2 Diagnostic Program
Dependencies: mbed
Revision 8:31dfba068a15, committed 2016-01-29
- Comitter:
- JordanWisdom
- Date:
- Fri Jan 29 20:48:18 2016 +0000
- Parent:
- 7:3ad02c0c93a9
- Commit message:
- Lab 2: 1-5 completed, 9 completed.; To Do: Lab 2, GMR, Optical Array
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 3ad02c0c93a9 -r 31dfba068a15 main.cpp --- a/main.cpp Thu Jan 28 21:56:41 2016 +0000 +++ b/main.cpp Fri Jan 29 20:48:18 2016 +0000 @@ -4,6 +4,7 @@ //DECLARATIONS Serial pc(USBTX, USBRX); +Serial BT(p28,p27); //Digital Inputs DigitalIn Sw1(p24); @@ -59,14 +60,16 @@ printf("\n\r-------------------------------------"); printf("\r\n Pressed Key = %c",Key); printf("\n\r-------------------------------------"); - AOutput.write(Key); + float K = Key; + AOutput.write(K/128); + printf("\n\rK = %2.2f",K); return 0; } int fAnalogIn(){ + printf("\n\r Pin 15 Input = %1.4f volts\n", AnaInput1.read()*3.3f); 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); + printf("\n\r Pin 16 Output = %1.4f volts\n", AnaInput2.read()*3.3f); return 0; } @@ -76,16 +79,21 @@ char T[4] = "500"; char PW[4] = "250"; printf("\n\r\n\r-----Robotics PWM Options-----"); - printf("\n\rEnter a Period in milliSeconds (max 999):"); + + printf("\n\rEnter a Period in microSeconds (max 999):"); pc.gets(T,4); - long int P = strtol(PW,NULL,10); - PWM.period_ms(P); - printf("\n\rEnter a Pulse Width in milliSeconds (max 999):"); - pc.scanf(PW,4); + long int P = strtol(T,NULL,10); + PWM.period_us(P); + + printf("\n\rEnter a Pulse Width in microSeconds (max 999):"); + pc.gets(PW,4); long int W = strtol(PW,NULL,10); - PWM.pulsewidth_ms(W); - printf("\n\rPeriod in Seconds: %i", P); - printf("\n\rPulse Width in Seconds: %i", W); + PWM.pulsewidth_us(W); + + printf("\n\rPeriod in uS: %i", P); + printf("\n\rPulse Width in uS: %i", W); + float R = W/P; + printf("\n\rDuty Cycle: %3.3f", R); return 0; @@ -93,6 +101,7 @@ int ExternalIntInit(){//initialize an external interrupt that causes an LED to toggle its state each //time an external interrupt is detected. + return 0; } @@ -127,13 +136,25 @@ return 0; } -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. - -return 0; +int BlueToothTest(){ + char x; + BT.baud(9600); + do{ + if (pc.readable()) { + x = pc.getc(); //read keypress + if(x == 13){ + BT.putc('\n'); //send to pc/mobile + pc.putc('\n'); //echo to pc + BT.putc('\r'); //send to pc/mobile + pc.putc('\r'); //echo to pc + } + else{ + BT.putc(x); //send to pc/mobile + pc.putc(x); //echo to pc + } + } + }while(x != 'q'); + return 0; } void scan(short ScanData[]) {