求助!求助!请大神赐教ardunio遥控蜂鸣器播放音乐的用法
本帖最后由 说书人 于 2016-12-4 19:05 编辑作为学生一枚,因完成作业的缘故,想要做一个用蜂鸣器播放遥控器遥控的播放器,固定音乐就行。麻烦各位大神教一下,非常感谢! 如果发出详细接入电路图和编码就更好了。
随便写的,你可以试试
#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 != 0)
{
str = toupper(str);
++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';
}
}
char _ABVAR_1_ircode = "";
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 );
} yuzhunyu 发表于 2016-12-5 09:21
随便写的,你可以试试
#include
#include
谢谢大神! 厉害大神 厉害大神
页:
[1]