STM32蓝牙小车实现按下前进松开停止
App是用App Inventor开发的,主要原理是当按键按下时发送一个数字,松开时再发送另外一个数字,松开时让小车停下,只有一直按着的时候小车才动。
App逻辑设置:
void USART1_IRQHandler(void)
{
u8 flag;
if(USART_GetITStatus(USART1,USART_IT_RXNE)!= RESET)
{
flag=USART_ReceiveData(USART1);
if(flag==0)
{
TIM_SetCompare1(TIM2,5000);//慢反
TIM_SetCompare2(TIM2,500);
TIM_SetCompare3(TIM2,5000);
TIM_SetCompare4(TIM2,500);
}
else if(flag==1)
{
TIM_SetCompare1(TIM2,500);//慢正
TIM_SetCompare2(TIM2,5000);
TIM_SetCompare3(TIM2,500);
TIM_SetCompare4(TIM2,5000);
}
else if(flag==2)
{
TIM_SetCompare1(TIM2,10000);//快反
TIM_SetCompare2(TIM2,500);
TIM_SetCompare3(TIM2,10000);
TIM_SetCompare4(TIM2,500);
}
else if(flag==3)
{
TIM_SetCompare1(TIM2,500);//快正
TIM_SetCompare2(TIM2,10000);
TIM_SetCompare3(TIM2,500);
TIM_SetCompare4(TIM2,10000);
}
else if(flag==4)
{
TIM_SetCompare1(TIM2,500);//左
TIM_SetCompare2(TIM2,5000);
TIM_SetCompare3(TIM2,500);
TIM_SetCompare4(TIM2,500);
}
else if(flag==5)
{
TIM_SetCompare1(TIM2,500);//右
TIM_SetCompare2(TIM2,500);
TIM_SetCompare3(TIM2,500);
TIM_SetCompare4(TIM2,5000);
}
else if(flag==6)
{
TIM_SetCompare1(TIM2,500);//停
TIM_SetCompare2(TIM2,500);
TIM_SetCompare3(TIM2,500);
TIM_SetCompare4(TIM2,500);
}
}
}
app及程序
链接:https://pan.baidu.com/s/16GWvQEosMU6op2phVubHnw
提取码:kac1
复制这段内容后打开百度网盘手机App,操作更方便哦