标题: 基于STM32单片机小车三路循迹代码 [打印本页]

作者: 想年薪五十万    时间: 2023-7-22 11:27
标题: 基于STM32单片机小车三路循迹代码
#include "stm32f10x.h"                  // Device header
#include "PWM.h"
#include "delay.h"
#include "Motor.h"
#include "RedRay.h"

//循迹,通过判断三个光电对管的状态来控制LED灯
void SearchRun(void)
{
    if(SEARCH_M_IO == BLACK_AREA && SEARCH_L_IO == BLACK_AREA && SEARCH_R_IO == BLACK_AREA )
    {
        if(SEARCH_M_IO == BLACK_AREA && SEARCH_L_IO == BLACK_AREA && SEARCH_R_IO == BLACK_AREA )
        {
        delay(10);
        Motor_R_SetSpeed(40);
        Motor_L_SetSpeed2(40);
        }
    }
   
     else if(SEARCH_L_IO == BLACK_AREA )
    {
        Motor_R_SetSpeed(60);
        Motor_L_SetSpeed2(40);
    }

     else if(SEARCH_R_IO == BLACK_AREA )
    {
        Motor_R_SetSpeed(40);
        Motor_L_SetSpeed2(60);
    }
   
}

int main()
{   

    Motor_Init();
    while(1)

    {
        SearchRun();
    }
   
}


原理图: 无
仿真: 无
Keil代码: 代码.7z (180.6 KB, 下载次数: 12)





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1