for test

Dependencies:   mbed

main.cpp

Committer:
jh_ndm
Date:
2016-07-15
Revision:
2:b67216fc6104
Parent:
1:2cd31d24d6fc
Child:
3:4132f3ef7d22

File content as of revision 2:b67216fc6104:



#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() {    
    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;          
        }  
    } 
}