当前位置:网站首页>技能梳理[email protected]语音模块+stm32+nfc
技能梳理[email protected]语音模块+stm32+nfc
2022-06-30 09:37:00 【Sky_Lannister】
小车nfc模块检测不同卡片播发不同声音,和上一个设计差不多,就是实现一个类似公交车刷卡播报到哪一战的效果
1、项目简介

2、实现逻辑
#见简介
3、应用场景
#公交站到站播报
4、核心代码梳理
//全局变量定义
unsigned int speed_count=0;//占空比计数器 50次一周期
char front_left_speed_duty=SPEED_DUTY;
char front_right_speed_duty=SPEED_DUTY;
char behind_left_speed_duty=SPEED_DUTY;
char behind_right_speed_duty=SPEED_DUTY;
unsigned char tick_5ms = 0;//5ms计数器,作为主函数的基本周期
unsigned char tick_1ms = 0;//1ms计数器,作为电机的基本计数器
unsigned char tick_200ms = 0;//刷新显示
char ctrl_comm = COMM_STOP;//控制指令
char ctrl_comm_last = COMM_STOP;//上一次的指令
unsigned char continue_time=0;
unsigned char bt_rec_flag=0;//蓝牙控制标志位
char id_sound = 0;
int main(void)
{
delay_init();
GPIOCLKInit();
UserLEDInit();
LCD1602Init();
//IRCtrolInit();
TIM2_Init();
MotorInit();
ServoInit();
MeasureInit();
RedRayInit();
//USART3Conf(9600);
USART2Conf(9600);
while(1)
{
if(tick_5ms >= 5)
{
tick_5ms = 0;
tick_200ms++;
if(tick_200ms >= 40)
{
tick_200ms = 0;
LEDToggle(LED_PIN);
LCD1602WriteSpeed(front_left_speed,front_right_speed);
}
// continue_time--;//200ms 无接收指令就停车
// if(continue_time == 0)
// {
// continue_time = 1;
// CarStop();
// }
//do something
MeasureSpeed();
LCD1602WriteCommand(ctrl_comm);
VoidRun();
}
///声音控制相关
if(id_sound != 0)
{
CarStop();
if(id_sound == 1)
{
IO1_RESET;
Delayms(2000);
}
else if(id_sound == 2)
{
IO2_RESET;
Delayms(2000);
}
else if(id_sound == 3)
{
IO3_RESET;
Delayms(2000);
}
Delayms(5000);
IO1_SET;
IO2_SET;
IO3_SET;
id_sound = 0;
}
}
}
void CarMove(void)
{
BEHIND_RIGHT_EN;
//左前轮
/* if(front_left_speed_duty > 0)//向前 { if(speed_count < front_left_speed_duty) { FRONT_LEFT_GO; } else { FRONT_LEFT_STOP; } } else if(front_left_speed_duty < 0)//向后 { if(speed_count < (-1)*front_left_speed_duty) { FRONT_LEFT_BACK; } else { FRONT_LEFT_STOP; } } else //停止 { FRONT_LEFT_STOP; } */
//右前轮
if(front_right_speed_duty > 0)//向前
{
if(speed_count < front_right_speed_duty)
{
FRONT_RIGHT_GO;
}else //停止
{
FRONT_RIGHT_STOP;
}
}
else if(front_right_speed_duty < 0)//向后
{
if(speed_count < (-1)*front_right_speed_duty)
{
FRONT_RIGHT_BACK;
}
else //停止
{
FRONT_RIGHT_STOP;
}
}
else //停止
{
FRONT_RIGHT_STOP;
}
//左后轮
if(behind_left_speed_duty > 0)//向前
{
if(speed_count < behind_left_speed_duty)
{
BEHIND_LEFT_GO;
}
else //停止
{
BEHIND_LEFT_STOP;
}
}
else if(behind_left_speed_duty < 0)//向后
{
if(speed_count < (-1)*behind_left_speed_duty)
{
BEHIND_LEFT_BACK;
}
else //停止
{
BEHIND_LEFT_STOP;
}
}
else //停止
{
BEHIND_LEFT_STOP;
}
//右后轮
/* if(behind_right_speed_duty > 0)//向前 { if(speed_count < behind_right_speed_duty) { BEHIND_RIGHT_GO; } else //停止 { BEHIND_RIGHT_STOP; } } else if(behind_right_speed_duty < 0)//向后 { if(speed_count < (-1)*behind_right_speed_duty) { BEHIND_RIGHT_BACK; } else //停止 { BEHIND_RIGHT_STOP; } } else //停止 { BEHIND_RIGHT_STOP; } */
}
//向前
void CarGo(void)
{
//front_left_speed_duty=SPEED_DUTY+30;
behind_left_speed_duty=SPEED_DUTY-10;
front_right_speed_duty=SPEED_DUTY-10;
//behind_right_speed_duty=SPEED_DUTY;
}
//后退
void CarBack(void)
{
//front_left_speed_duty=-SPEED_DUTY;
front_right_speed_duty=-SPEED_DUTY;
behind_left_speed_duty=-SPEED_DUTY;
//behind_right_speed_duty=-SPEED_DUTY;
}
//向左
void CarLeft(void)
{
//front_left_speed_duty=-10;
front_right_speed_duty=SPEED_DUTY+10;
behind_left_speed_duty=-30;
// behind_right_speed_duty=SPEED_DUTY+60;//增加后轮驱动力
}
//向右
void CarRight(void)
{
// front_left_speed_duty=SPEED_DUTY;
front_right_speed_duty=-20;
behind_left_speed_duty=SPEED_DUTY+5;//增加后轮驱动力
// behind_right_speed_duty=SPEED_DUTY;
}
//停止
void CarStop(void)
{
//front_left_speed_duty=0;
front_right_speed_duty=0;
behind_left_speed_duty=0;
// behind_right_speed_duty=0;
}
void MotorInit(void)
{
MotorGPIO_Configuration();
CarStop();
}
循迹,通过判断三个光电对管的状态来控制小车运动
void SearchRun(void)
{
//三路都检测到
if(SEARCH_L_IO == BLACK_AREA && SEARCH_M_IO == BLACK_AREA && SEARCH_R_IO == BLACK_AREA ) //三路黑线停止
{
CarStop();//ctrl_comm = COMM_UP; //前进
//return;
}
else if(SEARCH_L_IO == WHITE_AREA && SEARCH_M_IO ==BLACK_AREA && SEARCH_R_IO ==BLACK_AREA)//右
{
CarRight();//ctrl_comm = COMM_RIGHT;
}
else if(SEARCH_L_GPIO ==WHITE_AREA && SEARCH_M_IO ==WHITE_AREA && SEARCH_R_IO ==BLACK_AREA)
{
CarRight();
}
else if(SEARCH_L_IO == BLACK_AREA && SEARCH_M_IO ==BLACK_AREA && SEARCH_R_IO ==WHITE_AREA)//左
{
CarLeft();//ctrl_comm = COMM_LEFT;
}
else if(SEARCH_L_IO ==BLACK_AREA && SEARCH_M_IO ==WHITE_AREA && SEARCH_R_IO ==WHITE_AREA)
{
CarLeft();
}
else if( SEARCH_L_IO == WHITE_AREA && SEARCH_M_IO == BLACK_AREA && SEARCH_R_IO ==WHITE_AREA)//中
{
CarGo();//ctrl_comm = COMM_UP;
}
else if(SEARCH_L_IO ==BLACK_AREA && SEARCH_M_IO==WHITE_AREA && SEARCH_R_IO==BLACK_AREA)
{
CarGo();
}
else if(SEARCH_L_IO ==WHITE_AREA && SEARCH_M_IO ==WHITE_AREA && SEARCH_R_IO ==WHITE_AREA)
{
CarGo();
}
}
5、部分参考资料
#用的JQ8900-16P语音模块
#nfc模块也是现成的,检测到卡片通过串口向mcu发送卡号
6、注意事项
#卡号提前已经写死在小车程序里面了
完整可运行项目地址
边栏推荐
- 7. development of mobile login function
- 逸仙电商发布一季报:坚持研发及品牌投入,实现可持续高质量发展
- keras ‘InputLayer‘ object is not iterable
- GNN hands on practice (II): reproduction graph attention network gat
- 2022第六季完美童模 托克逊赛区 决赛圆满落幕
- 开源了!文心大模型ERNIE-Tiny轻量化技术,又准又快,效果全开
- Leetcode question brushing (III) -- binary search (go Implementation)
- Deployment of efficient and versatile clusters lvs+kept highly available clusters
- Oracle creates a stored procedure successfully, but the compilation fails
- Leetcode question brushing (I) -- double pointer (go Implementation)
猜你喜欢

How does the diode work?

孙安民作品《莲花净心》数字藏品上线长城数艺

MySQL log management, backup and recovery of databases (1)

The digital collection of sunanmin's lotus heart clearing was launched on the Great Wall Digital Art

调试方法和技巧详解

Brève description du collecteur d'ordures G1

Koreano essential creates a professional style

Great Wall digital art digital collection platform releases the creation Badge

unable to convert expression into double array

机器人系统动力学——惯性参数
随机推荐
Description of event flow
6. Redis new data type
Automated stock trading ensemble strategy based on Reinforcement Learning
Questions about cookies and sessions
Applying applet container technology to IOT ecological construction
“昆明城市咖啡地图”活动再度开启
C语言实现扫雷游戏,附详解及完整代码
华南产业集团发力数字经济,城链科技发布会成功召开
input限制输入
2022 Season 6 perfect children's model toxon division finals came to a successful conclusion
【C语言快速上手】带你了解C语言,零基础入门③
打通供应链 深圳礼品展助跨境电商寻破局之道
跳跃表介绍
G code explanation | list of the most important G code commands
"Hackers and painters" -- why not be stupid
Action bright: take good care of children's eyes together -- a summary of the field investigation on the implementation of action bright in Guangxi
Yixian e-commerce released its first quarterly report: adhere to R & D and brand investment to achieve sustainable and high-quality development
Use and description of event delegation
[JVM] G1 garbage collector
MySQL log management, backup and recovery of databases (1)