RobotHardware-UESTC/Hardware/Firmware/GeekRobotTiny_Firmware v1.0/User/main.c

78 lines
1.9 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/******************** (C) COPYRIGHT 2023 GeekRebot *****************************
* File Name : main.c
* Current Version : V1.0 & ST 3.5.0
* Author : zhanli 719901725@qq.com
* Date of Issued : 2023.04.06 zhanli: Create
* Comments : GeekRebot STM32固件
********************************************************************************/
#include "bsp_sys.h"
#include "stdio.h"
#include "bluetooth.h"
unsigned char BLE_RX[64];
/**----------------------------------------------------------------------
* Function : main
* Description : GeekRebot主函数
* Author : zhanli&719901725@qq.com
* Date : 2023/04/22 zhanli
*---------------------------------------------------------------------**/
int main(void)
{
// 初始化系统配置
System_Init();
// 蓝牙初始化
Bluetooth_Init(9600);
// 小车默认状态为停止
Car_Stop();
while (1)
{
Delay_ms(20);
USART2_Receive(BLE_RX, 6);// 蓝牙接收到的数据
USART2_Send(BLE_RX, 6); // 将蓝牙接收到的数据再通过HC-05发送出来观察不需要可以注释
//Delay_ms(500);
if((BLE_RX[3] == 0xB1)&&(BLE_RX[4]==0xB5))//加速
{
// SetPoint = SetPoint + 10;
BLE_RX[3] = 0x00;//清缓存
}
if((BLE_RX[3] == 0xB3)&&(BLE_RX[4]==0xB7))//减速
{
// SetPoint = SetPoint - 10;
BLE_RX[3] = 0x00;//清缓存
}
if((BLE_RX[3] == 0xB2)&&(BLE_RX[4]==0xB6))//前进
{
Car_Go();
}
if((BLE_RX[3] == 0xB4)&&(BLE_RX[4]==0xB8))//左转圈
{
Car_Turn_Left();
Delay_ms(500);//车无角度传感器,且由于车速不同,调整延时长短实现大概的转角 90度。
Car_Go();
BLE_RX[3] = 0x00;//清缓存
}
if((BLE_RX[3] == 0xB5)&&(BLE_RX[4]==0xB9))//停车
{
Car_Stop();
}
if((BLE_RX[3] == 0xB6)&&(BLE_RX[4]==0xBA))//右转圈
{
Car_Turn_Right();
Delay_ms(500);//车无角度传感器,且由于车速不同,调整延时长短实现大概的转角 90度。
Car_Go();
BLE_RX[3] = 0x00;//清缓存
}
if((BLE_RX[3] == 0xB8)&&(BLE_RX[4]==0xBC))//后退
{
Car_Back();
}
}
}