jiang hao
/
DFRobotMbedTest
for test
Revision 3:4132f3ef7d22, committed 2016-07-15
- Comitter:
- jh_ndm
- Date:
- Fri Jul 15 04:13:23 2016 +0000
- Parent:
- 2:b67216fc6104
- Commit message:
- timeout
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Jul 15 01:55:25 2016 +0000 +++ b/main.cpp Fri Jul 15 04:13:23 2016 +0000 @@ -4,86 +4,54 @@ Serial uart1(PA_13, PA_14); // tx, rx Serial uart2(PC_10, PC_11); // tx, rx -DigitalOut num1(D10); -DigitalOut num2(D11); -DigitalOut num3(D12); -DigitalOut num4(D2); -DigitalOut num5(D3); -DigitalOut num6(D5); -DigitalOut num7(D6); -AnalogIn battery1(A1); -AnalogIn battery2(A2); -AnalogIn battery3(A3); +DigitalOut myD1(D10); +DigitalOut myD2(D11); +DigitalOut myD3(D12); +DigitalOut myD4(D2); +AnalogIn myA1(A1); +AnalogIn myA2(A2); +AnalogIn myA3(A3); PwmOut PWM1(D3); PwmOut PWM2(D5); PwmOut PWM3(D6); -float pv1=0; -float pv2=0; -float pv3=0; + +Timeout timeout; + +void attimeout() +{ + myD1 = 0; + myD2 = 0; + myD3 = 0; + myD4 = 0; +} -int main() { +int main() { + uart1.baud(115200); + uart2.baud(115200); + PWM1.period_us(500); + PWM2.period_us(500); + PWM3.period_us(500); + PWM1 = 0.2; + PWM2 = 0.5; + PWM3 = 0.8; + uart2.printf("uart2:for Loopback test,please input something\n"); + uart1.printf("start testing uart1 digitalOut and PWM and analogIn\n"); while(1){ - uart2.printf("uart2:for Loopback test,please input something\n"); - char c = uart2.getc(); - uart2.printf("%c",c); - uart1.printf("uart1:The following is digitalOut test\n"); - wait(0.25); - num1 = 1; - num2 = 1; - num3 = 1; - num4 = 1; - num5 = 1; - num6 = 1; - num7 = 1; - wait(0.25); - num1 = 0; - num2 = 0; - num3 = 0; - num4 = 0; - num5 = 0; - num6 = 0; - num7 = 0; - uart1.printf("uart1:The following is battery A1 A2 A3 test\n"); - if(battery1 > 0.5){ - uart1.printf("uart1:%02f\n",battery1.read()*3.3); - wait(1); - } - if(battery2 > 0.5){ - uart1.printf("uart1:%02f\n",battery2.read()*3.3); - wait(1); - } - if(battery3 > 0.5){ - uart1.printf("uart1:%02f\n",battery3.read()*3.3); - wait(1); + while(uart2.readable()){ + uart2.printf("%c", uart2.getc()); } - uart1.printf("uart1:The following is pwm test\n"); - PWM1.period_us(100); - PWM2.period_us(100); - PWM3.period_us(100); - PWM1 = 0; - PWM2 = 0.25; - PWM3 = 0.5; - for(int i=0;i<1000;i++) - { - PWM1=pv1; - pv1=pv1+0.01; - wait(0.05); - if (pv1>1) - pv1=0; - - PWM2=pv2; - pv2=pv2+0.01; - wait(0.05); - if (pv2>1) - pv2=0; - - PWM3=pv3; - pv3=pv3+0.01; - wait(0.05); - if (pv3>1) - pv3=0; - } + timeout.attach(&attimeout,2); + + myD1 = 1; + myD2 = 1; + myD3 = 1; + myD4 = 1; + wait(0.25); + + uart1.printf("A1:%02f\n",myA1.read()*3.3); + uart1.printf("A2:%02f\n",myA2.read()*3.3); + uart1.printf("A3:%02f\n",myA3.read()*3.3); } }