[链接文本]([链接文本](``````
#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "LED.h"
#include "PWM.h"
#include "AD.h"
#include "OLED.h"
//uint8_t i;
uint16_t AD0, AD1, AD2, AD3, AD4;
int main(void)
{
int a=0;
OLED_Init();
AD_Init();
LED_Init();
PWM_Init();
LED1_ON();
LED1_OFF();
OLED_ShowString(1, 1, "AD4:");
OLED_ShowString(2, 1, "AD1:");
OLED_ShowString(3, 1, "AD2:");
OLED_ShowString(4, 1, "AD3:");
OLED_ShowString(1, 9, "D0:");
OLED_ShowString(2, 9, "a:");
while (1)
{
AD0 = AD_GetValue(ADC_Channel_2);//YOU2
AD1 = AD_GetValue(ADC_Channel_3);//YOU1
AD2 = AD_GetValue(ADC_Channel_4);//ZHONG
AD3 = AD_GetValue(ADC_Channel_5);//ZUO1
AD4 = AD_GetValue(ADC_Channel_6);//ZUO2
if(AD2<1000)//直走
{
TIM_SetCompare1(TIM2, 80); //YOULUN
TIM_SetCompare2(TIM2, 80);//ZUOLUN
}
else if(AD1<1000)//右转
{
TIM_SetCompare1(TIM2, 10);
TIM_SetCompare2(TIM2, 100);
}
else if(AD3<1000 ) //左转
{
TIM_SetCompare1(TIM2, 100);
TIM_SetCompare2(TIM2, 10 );
}
else
{
TIM_SetCompare1(TIM2,0);
TIM_SetCompare2(TIM2, 0 );
}
// if(AD4<1000) //左转DA
// {
// TIM_SetCompare1(TIM2, 90);
// TIM_SetCompare2(TIM2, 10 );
// }
if(AD4<1000 && AD2<1000 && a==0) //zuozhuanxiaoquan
{
a=1;
TIM_SetCompare1(TIM2,50);
TIM_SetCompare2(TIM2, 0 );
Delay_ms(500);
}
if(AD1<1000 && AD2<1000 &&AD3<1000 && a==1) //zuozhuanxiaoquan
{
a=2;
TIM_SetCompare1(TIM2,50);
TIM_SetCompare2(TIM2, 0 );
Delay_ms(500);
}
else if(AD2<1000 && AD1<1000 && AD3<1000&& a==2)
{
a=3;
Buzzer_ON();
Delay_ms (600);
Buzzer_OFF();
Delay_ms (100);
Buzzer_ON();
Delay_ms (100);
Buzzer_OFF();
Delay_ms (100);
Buzzer_ON();
Delay_ms (100);
Buzzer_OFF();
}
if(a==3 && AD2<1000 && AD1<1000 && AD3<1000)
{
TIM_SetCompare1(TIM2, 0);
TIM_SetCompare2(TIM2, 0 );
Delay_ms (3000);
TIM_SetCompare1(TIM2, 0);
TIM_SetCompare2(TIM2, 0 );
}
OLED_ShowNum(1, 5, AD4, 4);
OLED_ShowNum(2, 5, AD1, 4);
OLED_ShowNum(3, 5, AD2, 4);
OLED_ShowNum(4, 5, AD3, 4);
OLED_ShowNum(1, 10, AD0, 4);
OLED_ShowNum(2, 10, a, 4);
}
}