当前位置:网站首页>技能梳理[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、注意事项
#卡号提前已经写死在小车程序里面了
完整可运行项目地址
边栏推荐
- Regular expression Basics
- Deployment of efficient and versatile clusters lvs+kept highly available clusters
- G code explanation | list of the most important G code commands
- Es common curl finishing
- L'activité "Kunming City coffee map" a rouvert
- GD32 RT-Thread PWM驱动函数
- Description of event object
- GNN动手实践(二):复现图注意力网络GAT
- 孙安民作品《莲花净心》数字藏品上线长城数艺
- Highlight display of Jinbei LB box, adhering to mini special effects
猜你喜欢

MySQL advanced SQL statement of database (2)

移植完整版RT-Thread到GD32F4XX(详细)

South China Industrial Group launched digital economy and successfully held the city chain technology conference

G 代码解释|最重要的 G 代码命令列表

GNN hands on practice (II): reproduction graph attention network gat

Test memory read rate

光明行动:共同呵护好孩子的眼睛——广西实施光明行动实地考察调研综述

Basic MySQL operation commands of database

“昆明城市咖啡地圖”活動再度開啟

Great Wall digital art digital collection platform releases the creation Badge
随机推荐
机器人系统动力学——惯性参数
《锦绣中华》中老年公益文旅游-走进佛山敬老院
Compare the maximum computing power of the Cenozoic top ant s19xp and the existing s19pro in bitland
ModuleNotFoundError: No module named ‘_ swigfaiss‘
Get through the supply chain Shenzhen gift show helps cross-border e-commerce find ways to break the situation
Quick completion guide for mechanical arm (V): end effector
Applying applet container technology to IOT ecological construction
How does the diode work?
Great Wall digital art digital collection platform releases the creation Badge
keras ‘InputLayer‘ object is not iterable
Basic MySQL operation commands of database
The digital collection of sunanmin's lotus heart clearing was launched on the Great Wall Digital Art
Leetcode question brushing (II) -- sorting (go Implementation)
KOREANO ESSENTIAL打造气质职场范
Didn't receive robot state (joint angles) with recent timestamp within 1 seconds
‘Failed to fetch current robot state‘ when using the ‘plan_ kinematic_ path‘ service #868
Memorize the text and remember the words. Read the text and remember the words. Read the article and remember the words; 40 articles with 3500 words; 71 articles broke through the words in the middle
Harvester ch1 of CKB and HNS, connection tutorial analysis
MIT-6874-Deep Learning in the Life Sciences Week4
Why can't you rob scientists of NFT