#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "OLED.h"
#include "Motor.h"
#include "Servo.h"
#include "uart.h"
#include "PWM.h"
u16 Cx,Cy;
/**************************************************************************
摄像头传输数据 A为角度正负
B为角度大小
C,D,E分别为三个标志位(摄像头视野里总左向右依次三个)
F为停车标志位
**************************************************************************/
int a=0;
int b=0;
int c=0;
float Angle;
int main(void)
{
/**********************************************
定义蜂鸣器io口
**********************************************/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitTypeDef GPIO_Initstructure;
GPIO_Initstructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Initstructure.GPIO_Pin = GPIO_Pin_12;
GPIO_Initstructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_Initstructure);
GPIO_SetBits(GPIOB,GPIO_Pin_12);
Servo_Init();
Motor_Init1();
Motor_Init2();
USART1_Init();
OLED_Init();
while (1)
{
Servo_SetAngle(Angle);
// OLED_ShowSignedNum(1, 1, B, 3);
//
// OLED_ShowSignedNum(1, 6, C, 3);
// OLED_ShowSignedNum(2, 1, D, 3);
// OLED_ShowSignedNum(2, 6, E, 3);
//
// OLED_ShowSignedNum(3, 1, F, 3);
//
// OLED_ShowSignedNum(3, 6, a, 3);
/**********************************************
驱动
**********************************************/
if(F==1)//识别标志变量复复赋值
{
b=1;
}
if(b==0)//电机占空比
{
Motor_SetSpeed1(40);
Motor_SetSpeed2(40);
}
else if(b==1)//识别到标志位停车,蜂鸣器和灯光响应
{
Motor_SetSpeed1(0);
Motor_SetSpeed2(0);
GPIO_ResetBits(GPIOB,GPIO_Pin_12);
Delay_s(1);
GPIO_SetBits(GPIOB,GPIO_Pin_12);
Delay_s(6000);
}
/*******************************************
识别岔路第一次忽略第二次进入
*******************************************/
if(D==1&&E==1&&a==0)
{
Angle=0;
Delay_ms(800);
a++;
}
else
{
Angle=B;
}
}
}
L
leoraiiion
@leoraiiion
-
-
[链接文本]([链接文本](`````` #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); } }
华电杯yzx
循迹小车