for test

Dependencies:   mbed

Revision:
2:b67216fc6104
Parent:
1:2cd31d24d6fc
Child:
3:4132f3ef7d22
diff -r 2cd31d24d6fc -r b67216fc6104 main.cpp
--- a/main.cpp	Fri Jul 15 01:20:01 2016 +0000
+++ b/main.cpp	Fri Jul 15 01:55:25 2016 +0000
@@ -1,108 +1,92 @@
-/*
-#include "mbed.h"
-AnalogIn battery(A3);
-Serial uart1(PA_13,PA_14);
-int main(){
-    while(1){
-        if(battery > 0.5){
-            uart1.printf("%02f\n",battery.read()*3.3);
-            wait(1);
-        }
-    }
-}
-*/
-
-/********uart0 demo********
-#include "mbed.h"
- 
-Serial uart1(PA_13, PA_14); // tx, rx
 
-int main() {
-    pc.printf("Please input something\n");
- 
-    while(1) {
-        char c = uart1.getc();
-        uart1.printf("%s\n",c);
-    }
-}
-*/
 
-/********uart2 demo********
-#include "mbed.h"
- 
-Serial uart2(PC_10, PC_11); // tx, rx
-
-int main() {
-    uart2.printf("Please input something\n");
- 
-    while(1) {
-        char c = uart2.getc();
-        uart2.printf("%s\n",c);
-    }
-}
-*/
-
-/**********Digital demo**********
 #include "mbed.h"
 
+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);
+PwmOut PWM1(D3);
+PwmOut PWM2(D5);
+PwmOut PWM3(D6);
+float pv1=0;
+float pv2=0;
+float pv3=0;
 
-int main(){
+int main() {    
     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);
+        }
+        
+        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;          
+        }  
+    } 
 }
-*/
-
-/**********analog demo***********
-#include "mbed.h"
-AnalogIn battery5(A0);
-AnalogIn battery4(PC_9);
-AnalogIn battery3(D5);
-Serial uart1(PA_13,PA_14);
-//Serial pc(USBTX,USBRX);
-int main(){
-    while(1){
-        //if(battery3 > 0.5){
-           // uart1.printf("%f\n",battery3.read()*3.3);
-           // wait(0.2);
-       // }
-        //if(battery4 > 0.5){
-          //  uart1.printf("%f\n",battery4.read());
-            //wait(0.2);
-        //}
-        if(battery5 > 0.5){
-            uart1.printf("%f\n",battery5.read());
-            wait(0.2);
-        }
-    }
-}
-*/
 
 
-#include"mbed.h"
-AnalogIn battery(A2);
-Serial uart1(PA_13,PA_14);
-int main(){
-    while(1){
-        if(battery > 0.5){
-            uart1.printf("%f",battery.read());
-            wait(1);
-        }
-    }
-}
+
+