7750浏览
查看: 7750|回复: 4

[求助] 求助!求助!请大神赐教ardunio遥控蜂鸣器播放音乐的用法

[复制链接]
回帖奖励 4 创造力 回复本帖可获得 2 创造力奖励! 每人限 1 次
本帖最后由 说书人 于 2016-12-4 19:05 编辑

    作为学生一枚,因完成作业的缘故,想要做一个用蜂鸣器播放遥控器遥控的播放器,固定音乐就行。麻烦各位大神教一下,非常感谢!   如果发出详细接入电路图和编码就更好了。

yuzhunyu  见习技师

发表于 2016-12-5 09:21:14

回帖奖励 +2 创造力

随便写的,你可以试试
[mw_shl_code=applescript,true]#include <IRremote.h>
#include <ctype.h>
#include <Wire.h>

IRrecv __ab_irrecv(11);
void __ab_setupIrReceiver()
{
__ab_irrecv.enableIRIn();
__ab_irrecv.resume();
}
void charsToUpper(char *str)
{
int p=0;
while(str[p] != 0)
{
str[p] = toupper(str[p]);
++p;
}
}
void __ab_getIrCommand(char *receivedCommand)
{
decode_results result;
if (__ab_irrecv.decode(&result))
{
ltoa(result.value, receivedCommand, 16);
charsToUpper(receivedCommand);
__ab_irrecv.resume();
}
else
{
receivedCommand[0] = '\0';
}
}
char _ABVAR_1_ircode[64] = "";
void setup()
{
__ab_setupIrReceiver();
}
void newtone(int tonePin,int frequency, int duration)
{
pinMode(tonePin,OUTPUT);
int period = 1000000 / frequency;
int pulse = period / 2;
for (long i = 0; i < duration * 1000; i += period) {
digitalWrite(tonePin, HIGH);
delayMicroseconds(pulse);
digitalWrite(tonePin, LOW);
delayMicroseconds(pulse);
}
}
void loop()
{
__ab_getIrCommand(_ABVAR_1_ircode);
if (!( strlen(_ABVAR_1_ircode) == 0 ))
{
if (strcmp(_ABVAR_1_ircode, "FF30CF") == 0) //FF30CF 为遥控器按键的编码
{
newtone(8,440, 1000);
}
if (strcmp(_ABVAR_1_ircode, "FF18E7") == 0)
{
newtone(8,1000, 1000);
}
}
delay( 1000 );
}[/mw_shl_code]
回复

使用道具 举报

说书人  见习技师
 楼主|

发表于 2016-12-5 10:45:16

yuzhunyu 发表于 2016-12-5 09:21
随便写的,你可以试试
[mw_shl_code=applescript,true]#include
#include

谢谢大神!
回复

使用道具 举报

dsweiliang  初级技神

发表于 2016-12-8 16:39:58

回帖奖励 +2 创造力

厉害大神
回复

使用道具 举报

 初级技匠

发表于 2022-4-22 08:30:17

回帖奖励 +2 创造力

厉害大神
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail