当前位置:网站首页>技能梳理[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、注意事项
#卡号提前已经写死在小车程序里面了
完整可运行项目地址
边栏推荐
- 《锦绣中华》中老年公益文旅游-走进佛山敬老院
- Leetcode question brushing (III) -- binary search (go Implementation)
- South China Industrial Group launched digital economy and successfully held the city chain technology conference
- Who should the newly admitted miners bow to in front of the chip machine and the graphics card machine
- C语言实现扫雷游戏,附详解及完整代码
- Tooltips in the era of touch
- 机器人系统动力学——惯性参数
- Get through the supply chain Shenzhen gift show helps cross-border e-commerce find ways to break the situation
- 郭琳加冕 2022第三季完美大师 全球人气季军
- 长城数艺数字藏品平台发布创世徽章
猜你喜欢

How to seize the opportunity of NFT's "chaos"?
![[AGC] build service 3- authentication service example](/img/32/44547c00476a055557dd1790e18849.png)
[AGC] build service 3- authentication service example

Detailed explanation of commissioning methods and techniques

L'activité "Kunming City coffee map" a rouvert

Configure Yii: display MySQL extension module verification failed

The famous painter shiguoliang's "harvest season" digital collection was launched on the Great Wall Digital Art

Eth is not connected to the ore pool

6.Redis新数据类型

打通供应链 深圳礼品展助跨境电商寻破局之道

Get through the supply chain Shenzhen gift show helps cross-border e-commerce find ways to break the situation
随机推荐
Koreano essential creates a professional style
JS get the substring of the specified character position and the specified character position interval of the specified string [simple and detailed]
Go -- standard library sort package
Description of event flow
Use and description of event delegation
The preliminary round of the sixth season of 2022 perfect children's model Hefei competition area was successfully concluded
6.Redis新数据类型
input限制输入
Go -- maximum heap and minimum heap
L'activité "Kunming City coffee map" a rouvert
Splendid China: public welfare tourism for the middle-aged and the elderly - entering Foshan nursing home
[JVM] brief introduction to CMS
开源了!文心大模型ERNIE-Tiny轻量化技术,又准又快,效果全开
train_de.py: error: argument --save_steps: invalid int value: ‘$[$[889580/128/4]*10/2]‘
Rider打开Unity脚本后没有提示
Yixian e-commerce released its first quarterly report: adhere to R & D and brand investment to achieve sustainable and high-quality development
[C language quick start] let you know C language and get started with zero basics ③
"Kunming City coffee map" activity was launched again
MySQL advanced SQL statement of database (2)
GD32 RT-Thread OTA/Bootloader驱动函数