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.
Fork of W7500P_Digital_Analog_Serial_PWM by
main.cpp
00001 #include "mbed.h" 00002 00003 Serial uart0(PA_13, PA_14); // tx, rx 00004 Serial uart2(PC_10, PC_11); // tx, rx 00005 DigitalOut myD1(D10); 00006 DigitalOut myD2(D11); 00007 DigitalOut myD3(D12); 00008 DigitalOut myD4(D2); 00009 AnalogIn myA1(A1); 00010 AnalogIn myA2(A2); 00011 AnalogIn myA3(A3); 00012 PwmOut PWM1(D3); 00013 PwmOut PWM2(D5); 00014 PwmOut PWM3(D6); 00015 DigitalIn myButton(PC_06); 00016 00017 Timeout digitalTimeout; 00018 Timeout analogTimeout; 00019 void attimeoutD() 00020 { 00021 static int pos = 0; 00022 if(pos == 0){ 00023 myD1 = 0; 00024 myD2 = 0; 00025 myD3 = 0; 00026 myD4 = 0; 00027 }else{ 00028 myD1 = 1; 00029 myD2 = 1; 00030 myD3 = 1; 00031 myD4 = 1; 00032 } 00033 pos = !pos; 00034 digitalTimeout.attach(&attimeoutD,0.5); 00035 } 00036 void attimeoutA() 00037 { 00038 uart0.printf("A1:%02fV ",myA1.read()*3.3); 00039 uart0.printf("A2:%02fV ",myA2.read()*3.3); 00040 uart0.printf("A3:%02fV \r\n",myA3.read()*3.3); 00041 analogTimeout.attach(&attimeoutA,1); 00042 } 00043 00044 int main() { 00045 uart0.baud(9600); 00046 uart2.baud(9600); 00047 PWM1.period_us(500); 00048 PWM2.period_us(500); 00049 PWM3.period_us(500); 00050 PWM1 = 0.2; 00051 PWM2 = 0.5; 00052 PWM3 = 0.8; 00053 uart2.printf("uart2:for Loopback test,please input something\n"); 00054 uart0.printf("start testing digitalOut and PWM and analogIn\r\n"); 00055 digitalTimeout.attach(&attimeoutD,0.5); 00056 analogTimeout.attach(&attimeoutA,1); 00057 00058 while(1) { 00059 if (myButton == 0) { 00060 uart0.printf("User Button is Pressed!!!\r\n"); 00061 } 00062 if(uart2.readable()){ 00063 char ch = uart2.getc(); 00064 uart2.printf("%c", ch); 00065 } 00066 } 00067 }
Generated on Wed Jul 13 2022 22:23:25 by
1.7.2
