本网页已闲置超过3分钟,按键盘任意键或点击空白处,即可回到网页
最热资讯


亲,“电路城”已合并升级到更全、更大、更强的「新与非网」。点击查看「新与非网」
如何使用 CATALEX 的串行 Mp3 播放器
只需要一个库 ( #include <SoftwareSerial.h>),并且一些简单的函数:
如何使用 HC-SR04 超声波范围
不需要库,反正很容易使用。我刚刚把我之前的 hc-sr04 帖子放在这个函数中:
如何同时使用它们 版本 1:简单的 mp3 距离触发器
如果您还没有该库,请先安装它(<SoftwareSerial.h>)。
在这个版本的代码中,如果有东西接近 50 厘米,那么它会触发 mp3 音频。我用它用一个非常响亮的“惊喜混蛋”剪辑来吓唬我的室友。
注意:完整.ino 代码在下面的项目附件中。
如何同时使用版本 2 和 Disturbance mp3 距离触发器
此版本不关心距离,只检测读数之间的差异。如果错误突然触发,if(gap>20){....... 我们需要在循环外声明新变量。我在代码的开头这样做了。
int firstTime=0;//we need to declare firstTime outside the loop
long Distance,auxDistance,gap=0;
void loop()
{
Distance=measureDistance(trigPin,echoPin);//measure distance and store
gap=abs(Distance-auxDistance);// calculate the difference between now and last reading
if(firstTime==0){//necesary for stability things
auxDistance=Distance;
gap=0;
//does it only the first time after play a song to avoid first loop malfuntcion
firstTime++;
delay(1000);
}
if(gap>20){ //if distance variation is 20cm
sendCommand(CMD_PLAY_WITHFOLDER, 0X0201);//play the first song of the second folder
firstTime=0;//avoid errors!!we dont like errors
delay(2000);
}
Serial.print("New Distace:");//debugggggg
Serial.print(Distance);
Serial.print(" Old Distance: ");
Serial.print(auxDistance);
Serial.println(gap);
delay(300);
auxDistance=Distance;//store the value for the if() in the next loop
}
如何同时使用它们 版本 3:两个距离传感器
使用两个距离传感器,您实际上可以猜测运动的方向,因此我做了一个程序, 根据人的运动方向显示“ hello ”或“ bye”。
void loop()
{
Distance=measureDistance(trigPin,echoPin);//measure distance1 and store
Distance2=measureDistance(trigPin2,echoPin2);//measure distance2 and store
gap=abs(Distance-auxDistance);// calculate the difference between now and last reading
gap2=abs(Distance2-auxDistance2);// calculate the difference between now and last reading
if(firstTime==0){//necesary for stability things
auxDistance=Distance;
auxDistance2=Distance2;
gap=0;
gap2=0;
//does it only the first time after play a song to avoid first loop malfuntcion
firstTime++;
delay(2000);
}
if(gap>20 and gap2<20 ){ //if distance variation is 20cm
sendCommand(CMD_PLAY_WITHFOLDER, 0X0201);//play the first song of the second folder
firstTime=0;//avoid errors!!we dont like errors
Serial.println("RIGHT MOVEMENT DETECTED");
delay(2000);
}
if(gap2>20 and gap<20){ //if distance variation is 20cm
sendCommand(CMD_PLAY_WITHFOLDER, 0X0202);//play the second song of the second folder
firstTime=0;//avoid errors!!we dont like errors
Serial.println("LEFT MOVEMENT DETECTED");
delay(2000);
}
Serial.println("\\\\\\\\\\\\\\\\\\\\\\");//debugggggg
Serial.print(" New Distace:");//debugggggg
Serial.print(Distance);
Serial.print(" Old Distance: ");
Serial.print(auxDistance);
Serial.print(" GAP ");
Serial.println(gap);
Serial.print("New Distace2:");//debugggggg
Serial.print(Distance);
Serial.print(" Old Distance2: ");
Serial.print(auxDistance);
Serial.print(" GAP2 ");
Serial.println(gap);
Serial.println("\\\\\\\\\\\\\\\\\\\\\\");//debugggggg
delay(300);
auxDistance=Distance;//store the value for the if() in the next loop
auxDistance2=Distance2;//store the value for the if() in the next loop
}
Disturbance2=0;
left=0;
right=0;
delay(1000);//wait to avoid errors
}
delay(300);
auxDistance=Distance;//store the value for the if() in the next loop
auxDistance2=Distance2;//store the value for the if() in the next loop
}
如果您对此项目有任何想法、意见或问题,请在下方留言。
原文链接丨以上内容来源网络,如涉及侵权可联系删除。
零死角玩转stm32-高级篇之MP3(支持中英文、长短文件名)
2013-08-12
将取代MP3的AAC到底什么来头?
2017-05-18
Galaxy S9/S9+细节曝光:保留额耳机端口,屏占比更高,机身尺寸不变
2017-12-27
MMP3彻底死亡:亚马逊将从2019年开始不再提供音乐下载服务
2017-12-22
N101双擎玩家拆机体验
2012-08-24
讨论