jiang hao
/
DFRobotMbedTest
for test
main.cpp@3:4132f3ef7d22, 2016-07-15 (annotated)
- Committer:
- jh_ndm
- Date:
- Fri Jul 15 04:13:23 2016 +0000
- Revision:
- 3:4132f3ef7d22
- Parent:
- 2:b67216fc6104
timeout
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jh_ndm | 0:695e35fce077 | 1 | |
jh_ndm | 0:695e35fce077 | 2 | |
jh_ndm | 0:695e35fce077 | 3 | #include "mbed.h" |
jh_ndm | 0:695e35fce077 | 4 | |
jh_ndm | 2:b67216fc6104 | 5 | Serial uart1(PA_13, PA_14); // tx, rx |
jh_ndm | 2:b67216fc6104 | 6 | Serial uart2(PC_10, PC_11); // tx, rx |
jh_ndm | 3:4132f3ef7d22 | 7 | DigitalOut myD1(D10); |
jh_ndm | 3:4132f3ef7d22 | 8 | DigitalOut myD2(D11); |
jh_ndm | 3:4132f3ef7d22 | 9 | DigitalOut myD3(D12); |
jh_ndm | 3:4132f3ef7d22 | 10 | DigitalOut myD4(D2); |
jh_ndm | 3:4132f3ef7d22 | 11 | AnalogIn myA1(A1); |
jh_ndm | 3:4132f3ef7d22 | 12 | AnalogIn myA2(A2); |
jh_ndm | 3:4132f3ef7d22 | 13 | AnalogIn myA3(A3); |
jh_ndm | 2:b67216fc6104 | 14 | PwmOut PWM1(D3); |
jh_ndm | 2:b67216fc6104 | 15 | PwmOut PWM2(D5); |
jh_ndm | 2:b67216fc6104 | 16 | PwmOut PWM3(D6); |
jh_ndm | 3:4132f3ef7d22 | 17 | |
jh_ndm | 3:4132f3ef7d22 | 18 | Timeout timeout; |
jh_ndm | 3:4132f3ef7d22 | 19 | |
jh_ndm | 3:4132f3ef7d22 | 20 | void attimeout() |
jh_ndm | 3:4132f3ef7d22 | 21 | { |
jh_ndm | 3:4132f3ef7d22 | 22 | myD1 = 0; |
jh_ndm | 3:4132f3ef7d22 | 23 | myD2 = 0; |
jh_ndm | 3:4132f3ef7d22 | 24 | myD3 = 0; |
jh_ndm | 3:4132f3ef7d22 | 25 | myD4 = 0; |
jh_ndm | 3:4132f3ef7d22 | 26 | } |
jh_ndm | 0:695e35fce077 | 27 | |
jh_ndm | 3:4132f3ef7d22 | 28 | int main() { |
jh_ndm | 3:4132f3ef7d22 | 29 | uart1.baud(115200); |
jh_ndm | 3:4132f3ef7d22 | 30 | uart2.baud(115200); |
jh_ndm | 3:4132f3ef7d22 | 31 | PWM1.period_us(500); |
jh_ndm | 3:4132f3ef7d22 | 32 | PWM2.period_us(500); |
jh_ndm | 3:4132f3ef7d22 | 33 | PWM3.period_us(500); |
jh_ndm | 3:4132f3ef7d22 | 34 | PWM1 = 0.2; |
jh_ndm | 3:4132f3ef7d22 | 35 | PWM2 = 0.5; |
jh_ndm | 3:4132f3ef7d22 | 36 | PWM3 = 0.8; |
jh_ndm | 3:4132f3ef7d22 | 37 | uart2.printf("uart2:for Loopback test,please input something\n"); |
jh_ndm | 3:4132f3ef7d22 | 38 | uart1.printf("start testing uart1 digitalOut and PWM and analogIn\n"); |
jh_ndm | 0:695e35fce077 | 39 | while(1){ |
jh_ndm | 3:4132f3ef7d22 | 40 | while(uart2.readable()){ |
jh_ndm | 3:4132f3ef7d22 | 41 | uart2.printf("%c", uart2.getc()); |
jh_ndm | 2:b67216fc6104 | 42 | } |
jh_ndm | 2:b67216fc6104 | 43 | |
jh_ndm | 3:4132f3ef7d22 | 44 | timeout.attach(&attimeout,2); |
jh_ndm | 3:4132f3ef7d22 | 45 | |
jh_ndm | 3:4132f3ef7d22 | 46 | myD1 = 1; |
jh_ndm | 3:4132f3ef7d22 | 47 | myD2 = 1; |
jh_ndm | 3:4132f3ef7d22 | 48 | myD3 = 1; |
jh_ndm | 3:4132f3ef7d22 | 49 | myD4 = 1; |
jh_ndm | 3:4132f3ef7d22 | 50 | wait(0.25); |
jh_ndm | 3:4132f3ef7d22 | 51 | |
jh_ndm | 3:4132f3ef7d22 | 52 | uart1.printf("A1:%02f\n",myA1.read()*3.3); |
jh_ndm | 3:4132f3ef7d22 | 53 | uart1.printf("A2:%02f\n",myA2.read()*3.3); |
jh_ndm | 3:4132f3ef7d22 | 54 | uart1.printf("A3:%02f\n",myA3.read()*3.3); |
jh_ndm | 2:b67216fc6104 | 55 | } |
jh_ndm | 0:695e35fce077 | 56 | } |
jh_ndm | 0:695e35fce077 | 57 | |
jh_ndm | 0:695e35fce077 | 58 | |
jh_ndm | 2:b67216fc6104 | 59 | |
jh_ndm | 2:b67216fc6104 | 60 |