Arduino的红外遥控器和RGB LED的 [英] Arduino IR remote and RGB LEDs
问题描述
我有一个车载MP3红外遥控器(有一些其他模块得到了它)和一个红外接收器。
我的第一个问题是(没有解决)
这是红外接收器接收突然改变(十进制)的值。这怎么可能?
的#define buttonOff 16738455 //< - 这个值改变
第二问题,我想不出(解决)
假设我有一个数组:
INT rgbcolors = {{R1,G1,B1},{R2,G2,B2},{R3,G3,B3},{氡,GN,BN}}
如何在这个数组由pressing 1按钮遥控器上的价值我周期?
这样pressing一次,给人的第一{R1,G1,B1},pressing两次,给出{R2,G2,B2}等...
为predefined颜色我现在的无效循环:
如果(irrecv.de code(安培;结果))
{
INT I = 0;
INT J = 0;
INT K = 0; unsigned int类型VAL = results.value;
irrecv.resume(); 开关(VAL){
案例BUTTON1:// RED
analogWrite(RedPin,255);
analogWrite(GreenPin,0);
analogWrite(BluePin,0);
打破;
案例按钮2:// GREEN
analogWrite(RedPin,0);
analogWrite(GreenPin,255);
analogWrite(BluePin,0);
打破;
案例按钮3:// BLUE
analogWrite(RedPin,0);
analogWrite(GreenPin,0);
analogWrite(BluePin,255);
打破;
案件将Button4:// YEL0
analogWrite(RedPin,255);
analogWrite(GreenPin,255);
analogWrite(BluePin,0);
打破;
案例button5:// PURPLE
analogWrite(RedPin,255);
analogWrite(GreenPin,0);
analogWrite(BluePin,255);
打破;
案例button6://绿松石
analogWrite(RedPin,0);
analogWrite(GreenPin,255);
analogWrite(BluePin,255);
打破;
案例button7:// ORANGE
analogWrite(RedPin,255);
analogWrite(GreenPin,140);
analogWrite(BluePin,0);
打破;
案例按钮8:// LIME!不要使用//崩溃
analogWrite(RedPin,133);
analogWrite(GreenPin,255);
analogWrite(BluePin,140);
打破;
案例按钮9:// PINK
analogWrite(RedPin,50);
analogWrite(GreenPin,50);
analogWrite(BluePin,50);
打破;
案例buttonOn:
analogWrite(RedPin,255);
analogWrite(GreenPin,255);
analogWrite(BluePin,255);
打破;
案例buttonOff:
analogWrite(RedPin,0);
analogWrite(GreenPin,0);
analogWrite(BluePin,0);
打破; }}
可惜我不能帮你IR接收器值突然改变的问题,但我想我可以通过这个数组的价值观与你的循环帮助pressing遥控器上的问题1按钮。以下是code样品,做什么,我想你想做的事:
const int的NumberOfModes = 4;
INT CURRENTMODE = -1;空隙环(){ 诠释rgbcolors [NumberOfModes] [3] = {
{} 255,0,0,// RED
{} 0,255,0,// GREEN
{} 0,0,255,// BLUE
{255,255,0} // YELLOW
}; 如果(irrecv.de code(安培;结果))
{
unsigned int类型VAL = results.value;
irrecv.resume(); 如果(VAL ==按钮1){ //切换到新模式
CURRENTMODE ++;
如果(CURRENTMODE> = NumberOfModes)
{
CURRENTMODE = 0;
} //设置输出值
analogWrite(RedPin,rgbcolors [CURRENTMODE] [0]);
analogWrite(GreenPin,rgbcolors [CURRENTMODE] [1]);
analogWrite(BluePin,rgbcolors [CURRENTMODE] [2]);
} }
}
I have a CAR MP3 IR Remote (got it with some other modules) and a IR receiver.
My first problem is (UNSOLVED)
The values that the IR receiver received suddenly changed (decimal). How is this possible?
#define buttonOff 16738455 //<-- this value changed
Second problem I can't figure out (SOLVED)
Suppose I have an array:
int rgbcolors = {{R1,G1,B1},{R2,G2,B2},{R3,G3,B3},{Rn,Gn,Bn}}
How do I cycle through the values of this array by pressing 1 button on the remote? So pressing once, gives the first {R1,G1,B1}, pressing twice, gives {R2,G2,B2} etc...
My current void loop for predefined colors:
if (irrecv.decode(&results))
{
int i = 0;
int j = 0;
int k = 0;
unsigned int val = results.value;
irrecv.resume();
switch(val) {
case button1: //RED
analogWrite(RedPin,255);
analogWrite(GreenPin,0);
analogWrite(BluePin,0);
break;
case button2: //GREEN
analogWrite(RedPin,0);
analogWrite(GreenPin,255);
analogWrite(BluePin,0);
break;
case button3: //BLUE
analogWrite(RedPin,0);
analogWrite(GreenPin,0);
analogWrite(BluePin,255);
break;
case button4: //YEL0
analogWrite(RedPin,255);
analogWrite(GreenPin,255);
analogWrite(BluePin,0);
break;
case button5: //PURPLE
analogWrite(RedPin,255);
analogWrite(GreenPin,0);
analogWrite(BluePin,255);
break;
case button6: //TURQUOISE
analogWrite(RedPin,0);
analogWrite(GreenPin,255);
analogWrite(BluePin,255);
break;
case button7: //ORANGE
analogWrite(RedPin,255);
analogWrite(GreenPin,140);
analogWrite(BluePin,0);
break;
case button8: //LIME !!! DON'T USE // CRASHES
analogWrite(RedPin,133);
analogWrite(GreenPin,255);
analogWrite(BluePin,140);
break;
case button9: //PINK
analogWrite(RedPin,50);
analogWrite(GreenPin,50);
analogWrite(BluePin,50);
break;
case buttonOn:
analogWrite(RedPin,255);
analogWrite(GreenPin,255);
analogWrite(BluePin,255);
break;
case buttonOff:
analogWrite(RedPin,0);
analogWrite(GreenPin,0);
analogWrite(BluePin,0);
break;
}
}
I unfortunately cannot help you with your "IR receiver value suddenly changed" issue, but I think I can help with your "cycle through the values of this array by pressing 1 button on the remote" question. The following is a code sample that does what I think you want to do:
const int NumberOfModes = 4;
int CurrentMode = -1;
void loop() {
int rgbcolors[NumberOfModes][3] = {
{ 255,0,0 }, // RED
{ 0,255,0 }, // GREEN
{ 0,0,255 }, // BLUE
{ 255,255,0 } // YELLOW
};
if (irrecv.decode(&results))
{
unsigned int val = results.value;
irrecv.resume();
if (val == button1) {
// Switch to new mode
CurrentMode++;
if (CurrentMode >= NumberOfModes)
{
CurrentMode = 0;
}
// Set output values
analogWrite(RedPin, rgbcolors[CurrentMode][0]);
analogWrite(GreenPin, rgbcolors[CurrentMode][1]);
analogWrite(BluePin, rgbcolors[CurrentMode][2]);
}
}
}
这篇关于Arduino的红外遥控器和RGB LED的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!