![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
release
Fork of W7500P_Digital_Analog_Serial_PWM by
main.cpp@5:608466ce27ff, 2016-07-15 (annotated)
- Committer:
- dfrobot
- Date:
- Fri Jul 15 08:15:37 2016 +0000
- Revision:
- 5:608466ce27ff
- Parent:
- 4:d5bf98a13160
change to uart0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jh_ndm | 0:695e35fce077 | 1 | #include "mbed.h" |
dfrobot | 4:d5bf98a13160 | 2 | |
dfrobot | 5:608466ce27ff | 3 | Serial uart0(PA_13, PA_14); // tx, rx |
jh_ndm | 2:b67216fc6104 | 4 | Serial uart2(PC_10, PC_11); // tx, rx |
dfrobot | 3:a005efbb789e | 5 | DigitalOut myD1(D10); |
dfrobot | 3:a005efbb789e | 6 | DigitalOut myD2(D11); |
dfrobot | 3:a005efbb789e | 7 | DigitalOut myD3(D12); |
dfrobot | 3:a005efbb789e | 8 | DigitalOut myD4(D2); |
dfrobot | 3:a005efbb789e | 9 | AnalogIn myA1(A1); |
dfrobot | 3:a005efbb789e | 10 | AnalogIn myA2(A2); |
dfrobot | 3:a005efbb789e | 11 | AnalogIn myA3(A3); |
jh_ndm | 2:b67216fc6104 | 12 | PwmOut PWM1(D3); |
jh_ndm | 2:b67216fc6104 | 13 | PwmOut PWM2(D5); |
jh_ndm | 2:b67216fc6104 | 14 | PwmOut PWM3(D6); |
dfrobot | 4:d5bf98a13160 | 15 | DigitalIn myButton(PC_06); |
dfrobot | 4:d5bf98a13160 | 16 | |
dfrobot | 4:d5bf98a13160 | 17 | Timeout digitalTimeout; |
dfrobot | 4:d5bf98a13160 | 18 | Timeout analogTimeout; |
dfrobot | 4:d5bf98a13160 | 19 | void attimeoutD() |
dfrobot | 4:d5bf98a13160 | 20 | { |
dfrobot | 4:d5bf98a13160 | 21 | static int pos = 0; |
dfrobot | 4:d5bf98a13160 | 22 | if(pos == 0){ |
dfrobot | 4:d5bf98a13160 | 23 | myD1 = 0; |
dfrobot | 4:d5bf98a13160 | 24 | myD2 = 0; |
dfrobot | 4:d5bf98a13160 | 25 | myD3 = 0; |
dfrobot | 4:d5bf98a13160 | 26 | myD4 = 0; |
dfrobot | 4:d5bf98a13160 | 27 | }else{ |
dfrobot | 4:d5bf98a13160 | 28 | myD1 = 1; |
dfrobot | 4:d5bf98a13160 | 29 | myD2 = 1; |
dfrobot | 4:d5bf98a13160 | 30 | myD3 = 1; |
dfrobot | 4:d5bf98a13160 | 31 | myD4 = 1; |
dfrobot | 4:d5bf98a13160 | 32 | } |
dfrobot | 4:d5bf98a13160 | 33 | pos = !pos; |
dfrobot | 4:d5bf98a13160 | 34 | digitalTimeout.attach(&attimeoutD,0.5); |
dfrobot | 4:d5bf98a13160 | 35 | } |
dfrobot | 4:d5bf98a13160 | 36 | void attimeoutA() |
dfrobot | 4:d5bf98a13160 | 37 | { |
dfrobot | 5:608466ce27ff | 38 | uart0.printf("A1:%02fV ",myA1.read()*3.3); |
dfrobot | 5:608466ce27ff | 39 | uart0.printf("A2:%02fV ",myA2.read()*3.3); |
dfrobot | 5:608466ce27ff | 40 | uart0.printf("A3:%02fV \r\n",myA3.read()*3.3); |
dfrobot | 4:d5bf98a13160 | 41 | analogTimeout.attach(&attimeoutA,1); |
dfrobot | 4:d5bf98a13160 | 42 | } |
dfrobot | 4:d5bf98a13160 | 43 | |
dfrobot | 3:a005efbb789e | 44 | int main() { |
dfrobot | 5:608466ce27ff | 45 | uart0.baud(9600); |
dfrobot | 4:d5bf98a13160 | 46 | uart2.baud(9600); |
dfrobot | 3:a005efbb789e | 47 | PWM1.period_us(500); |
dfrobot | 3:a005efbb789e | 48 | PWM2.period_us(500); |
dfrobot | 3:a005efbb789e | 49 | PWM3.period_us(500); |
dfrobot | 3:a005efbb789e | 50 | PWM1 = 0.2; |
dfrobot | 4:d5bf98a13160 | 51 | PWM2 = 0.5; |
dfrobot | 3:a005efbb789e | 52 | PWM3 = 0.8; |
dfrobot | 3:a005efbb789e | 53 | uart2.printf("uart2:for Loopback test,please input something\n"); |
dfrobot | 5:608466ce27ff | 54 | uart0.printf("start testing digitalOut and PWM and analogIn\r\n"); |
dfrobot | 4:d5bf98a13160 | 55 | digitalTimeout.attach(&attimeoutD,0.5); |
dfrobot | 4:d5bf98a13160 | 56 | analogTimeout.attach(&attimeoutA,1); |
dfrobot | 4:d5bf98a13160 | 57 | |
dfrobot | 4:d5bf98a13160 | 58 | while(1) { |
dfrobot | 4:d5bf98a13160 | 59 | if (myButton == 0) { |
dfrobot | 5:608466ce27ff | 60 | uart0.printf("User Button is Pressed!!!\r\n"); |
dfrobot | 4:d5bf98a13160 | 61 | } |
dfrobot | 4:d5bf98a13160 | 62 | if(uart2.readable()){ |
dfrobot | 4:d5bf98a13160 | 63 | char ch = uart2.getc(); |
dfrobot | 4:d5bf98a13160 | 64 | uart2.printf("%c", ch); |
dfrobot | 4:d5bf98a13160 | 65 | } |
dfrobot | 4:d5bf98a13160 | 66 | } |
dfrobot | 4:d5bf98a13160 | 67 | } |