RBG LEDs IR remote control

my goal was that with an IR remote control make the LEDs rbg connects without . But to make this program gives me an error that I do not know how to do.

sketch_jan13b.ino (3.3 KB)

Não sei exactamente porque é que o post está em inglês na secção em português do fórum, mas de qualquer forma aqui vai. Como se mostra seguidamente, o código é compilado correctamente, mas duvido que funcione. Tive de eliminar um dos cases no switch (não estão definidos as opções BUTTON_CH- e BUTTON_CH+, e de qualquer forma, não pode ser utilizados os caracteres '+' e '-').

#include <IRremote.h>


#define NUM_BUTTONS 18
int resultCode;
const uint16_t BUTTON_PLAY = 0xFD40BF; // i.e. 0x10EFD827
const uint16_t BUTTON_CH = 0xFD708F;
const uint16_t BUTTON_CHMAIS = 0xFD50AF;
const uint16_t BUTTON_EQ = 0xFD20DF;
const uint16_t BUTTON_VOL = 0xFD609F;
const uint16_t BUTTON_VOLMAIS = 0xFD906F;
const uint16_t BUTTON_PREV = 0xFD807F;
const uint16_t BUTTON_NEXT = 0xFDA05F;
const uint16_t BUTTON_0 = 0xFDB04F;
const uint16_t BUTTON_1 = 0xFD00FF;
const uint16_t BUTTON_2 = 0xFD18E7;
const uint16_t BUTTON_3 = 0xFD9867;
const uint16_t BUTTON_4 = 0xFD6897;
const uint16_t BUTTON_5 = 0xFD58A7;
const uint16_t BUTTON_6 = 0xFDA857;
const uint16_t BUTTON_7 = 0xFD28D7;
const uint16_t BUTTON_8 = 0xFD08F7;
const uint16_t BUTTON_9 = 0xFD8877;
const uint16_t BUTTON_VER =0xFD48B7;
/* conectara a saída do recptor diodo IR ao pino 11*/
#define RECV_PIN 11
IRrecv irrecv(RECV_PIN);
decode_results results; // This will store our IR received codes
uint16_t lastCode = 0; 

/* Configuração RGB pinos LED:*/
enum ledOrder
{
  RED,   // 0
  GREEN, // 1
  BLUE   // 2
};
const int rgbPins[3] = {
  5, 9, 6}; // Vermelho, verde, azul, respectivamente pins
byte rgbValues[3] = {
  55, 23, 200}; //Isso mantém o controle de brilho canal
byte activeChannel = RED; // Comece com RED como o canal ativo
boolean ledEnable = 1; // Comece com o LED

void setup()
{
  Serial.begin(9600); // Use série de depurar
  irrecv.enableIRIn(); // Comece o receptor 

  /*Configure os pinos de LED RGB: */
  for (int i=0; i<3; i++)
  {
    pinMode(rgbPins[i], OUTPUT);
    analogWrite(rgbPins[i], rgbValues[i]);
  }
}

//verifica constantemente para qualquer recebeu códigos IR
// Fim ele atualiza o LED RGB
void loop() 
{
  if (irrecv.decode(&results)) 
  {
    uint16_t resultCode = (results.value & 0xFFFF);

    /* O controle remoto continuará a cuspir 0xFFFFFFFF se um
     botão é pressionado. Se conseguirmos 0xFFFFFFF , vamos apenas
     assumir o botão pressionado anteriormente está sendo pressionado */

    if (resultCode == 0xFFFF)
      resultCode = lastCode;
    else
      lastCode = resultCode;
  }
  // Essa instrução switch verifica o código IR recebido contra
  // Todos os códigos conhecidos . Cada botão de imprensa produz um
  // Saída em série , e tem um efeito sobre a saída do LED 

  switch (resultCode)
  {
  case BUTTON_PLAY:
    Serial.println("PLAY");
    if (ledEnable) ledEnable = 0;
    else ledEnable = 1; // Flip ledEnable
    break;
  case BUTTON_CH:
    Serial.println("CH-");
    activeChannel = RED;
    break;
    //      case BUTTON_CH:
    //        Serial.println("CH+");
    //        activeChannel = GREEN;
    //        break;
  case BUTTON_EQ:
    Serial.println("EQ");
    activeChannel = BLUE;
    break;
  default:
    Serial.print("Unrecognized code received: 0x");
    Serial.println(results.value, HEX);
    break;        
  }    
  irrecv.resume(); // Receive the next value


    // Every time through the loop, update the RGB LEDs:
  if (ledEnable)
  {
    for (int i=0; i<3; i++)
    {
      analogWrite(rgbPins[i], rgbValues[i]);
    }
  }
  else
  {
    for (int i=0; i<3; i++)
    {
      analogWrite(rgbPins[i], 0);
    }
  }
}

Obrigado, continua-me a dar erro
" Multiple libraries were found for "IRremote.h"
Utilizado: C:\Users\Daniela Vieira\Documents\Arduino\libraries\IRremote
Não utilizado: C:\Program Files (x86)\Arduino\libraries\RobotIRremote
exit status 1
Erro ao compilar."

A mensagem diz tudo. Tem várias bibliotecas com o mesmo nome. Apague a pasta: "C:\Program Files (x86)\Arduino\libraries\RobotIRremote" (ou mova para fora da pasta "libraries"), e o programa irá compilar.

obrigado, agora sim já não da erro nenhum.
Para fazer a mesma coisa mas com led's normais, a programação poderá ser a mesma?

A mesma coisa com LED's normais nao vai funcionar... :confused:

então como posso fazer???
eu queria meter todo na mesma programação onde tinha led's rgb, led's normais e servomotores é possível fazer isso??

Ahh, nao estavas a falar dos LED's IR... Desculpa, confundi.

Nesse caso, basta ligares um LED em cada um dos pinos onde ligaste o RGB.

fiz desta maneira para os led's rgb e led's normais.
como posso fazer a parte dos servomotores?

#include <IRremote.h>
#include <IRremoteInt.h>

#define NUM_BUTTONS 19
int resultCode;
const uint16_t BUTTON_PLAY = 0xFD40BF; // i.e. 0x10EFD827
const uint16_t BUTTON_CH = 0xFD708F;
const uint16_t BUTTON_CHMAIS = 0xFD50AF;
const uint16_t BUTTON_EQ = 0xFD20DF;
const uint16_t BUTTON_VOL = 0xFD609F;
const uint16_t BUTTON_VOLMAIS = 0xFD906F;
const uint16_t BUTTON_PREV = 0xFD807F;
const uint16_t BUTTON_NEXT = 0xFDA05F;
const uint16_t BUTTON_0 = 0xFDB04F;
const uint16_t BUTTON_1 = 0xFD00FF;
const uint16_t BUTTON_2 = 0xFD18E7;
const uint16_t BUTTON_3 = 0xFD9867;
const uint16_t BUTTON_4 = 0xFD6897;
const uint16_t BUTTON_5 = 0xFD58A7;
const uint16_t BUTTON_6 = 0xFDA857;
const uint16_t BUTTON_7 = 0xFD28D7;
const uint16_t BUTTON_8 = 0xFD08F7;
const uint16_t BUTTON_9 = 0xFD8877;
const uint16_t BUTTON_VER =0xFD48B7;
/* conectara a saída do recptor diodo IR ao pino 11*/
#define RECV_PIN 11
IRrecv irrecv(RECV_PIN);
decode_results results; // This will store our IR received codes
uint16_t lastCode = 0;

/* Configuração RGB pinos LED:*/
enum ledOrder
{
RED, // 0
GREEN, // 1
BLUE, // 2
led1, // 3
led2, // 4
led3, // 5
led4, // 6
led5, // 7
led6, // 8
led7, // 9
led8, // 10
led9, // 11
led10, // 12
led11, // 13
led12, // 14
};
const int ledPins[15] = {
22, 24, 26, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; // Vermelho, verde, azul, respectivamente pins
byte ledValues[3] = {
55, 23, 200}; //Isso mantém o controle de brilho canal
byte activeChannel = RED; // Comece com RED como o canal ativo
boolean ledEnable = 1; // Comece com o LED

void setup()
{
Serial.begin(9600); // Use série de depurar
irrecv.enableIRIn(); // Comece o receptor

/Configure os pinos de LED RGB: /
for (int i=0; i<3; i++)
{
pinMode(ledPins
, OUTPUT);

analogWrite(ledPins_, ledValues*);
}
}
//verifica constantemente para qualquer recebeu códigos IR*
// Fim ele atualiza o LED RGB
void loop()
{
* if (irrecv.decode(&results))
{_
uint16_t resultCode = (results.value & 0xFFFF);
_ / O controle remoto continuará a cuspir 0xFFFFFFFF se um_

* botão é pressionado. Se conseguirmos 0xFFFFFFF , vamos apenas*
_ assumir o botão pressionado anteriormente está sendo pressionado /
if (resultCode == 0xFFFF)
resultCode = lastCode;
else*
* lastCode = resultCode;
}
// Essa instrução switch verifica o código IR recebido contra*
* // Todos os códigos conhecidos . Cada botão de imprensa produz um*
* // Saída em série , e tem um efeito sobre a saída do LED*
* switch (resultCode)
{_
case BUTTON_PLAY:
_ Serial.println("PLAY");
if (ledEnable) ledEnable = 0;
else ledEnable = 1; // Flip ledEnable*
* break;_
case BUTTON_CH:
_ Serial.println("CH");
activeChannel = RED;
break;_
// case BUTTON_CH:
_ // Serial.println("CH+");
// activeChannel = GREEN;
// break;_
case BUTTON_EQ:
_ Serial.println("EQ");
activeChannel = BLUE;
break;
case BUTTON_0:
Serial.println("0");
activeChannel = led1;
break;_
// case BUTTON_0:
_ // Serial.println("CH+");
// activeChannel = LED2;
// break;_
case BUTTON_1:
_ Serial.println("1");
activeChannel = led3;
break;_
case BUTTON_2:
_ Serial.println("2");
activeChannel = led4;
break;_
case BUTTON_3:
_ Serial.println("3");
activeChannel = led4;
break;_
case BUTTON_4:
_ Serial.println("4");
activeChannel = led5;
break;_
case BUTTON_5:
_ Serial.println("5");
activeChannel = led6;
break;_
case BUTTON_6:
_ Serial.println("6");
activeChannel = led7;
break;_
case BUTTON_7:
_ Serial.println("7");
activeChannel = led8;
break;_
case BUTTON_8:
_ Serial.println("8");
activeChannel = led9;
break;_
case BUTTON_9:
_ Serial.println("9");
activeChannel = led10;
break;_
case BUTTON_VOL:
_ Serial.println("VOL");
activeChannel = led11;
break;_
case BUTTON_VOLMAIS:
_ Serial.println("VOLMAIS");
activeChannel = led12;
break;
default:
Serial.print("Unrecognized code received: 0x");
Serial.println(results.value, HEX);
break;
}
irrecv.resume(); // Receive the next value*
* // Every time through the loop, update the RGB LEDs:
if (ledEnable)
{
for (int i=0; i<3; i++)
{
analogWrite(ledPins, ledValues);
}
}
else*

* {
for (int i=0; i<3; i++)
{
analogWrite(ledPins, 0);
}
}
}*_

podem ajudar-me a perceber qual é o erro e porque
o erro que da é este " pro:10: error: 'FD00FF' was not declared in this scope
pro:11: error: 'FD807F' was not declared in this scope
pro:12: error: 'FD40BF' was not declared in this scope
pro:13: error: 'FD20DF' was not declared in this scope
pro:14: error: 'FDA05F' was not declared in this scope
pro:15: error: 'FD609F' was not declared in this scope
pro:16: error: 'FD10EF' was not declared in this scope
pro:17: error: 'FD906F' was not declared in this scope
pro:18: error: 'FD50AF' was not declared in this scope
pro:19: error: 'FDB04F' was not declared in this scope
pro:20: error: 'FD708F' was not declared in this scope
pro:21: error: 'FD30CF' was not declared in this scope
pro:22: error: 'FD08F7' was not declared in this scope
pro:23: error: 'FD8877' was not declared in this scope
pro:24: error: 'FD48B7' was not declared in this scope
pro:25: error: 'FD28D7' was not declared in this scope
pro:26: error: 'FDA857' was not declared in this scope
pro:27: error: 'FD6897' was not declared in this scope
pro:28: error: 'FD18EF' was not declared in this scope
pro:29: error: 'FD9867' was not declared in this scope
pro:30: error: 'FD58A7' was not declared in this scope
pro.ino: In function 'void loop()':
pro:92: error: case label does not reduce to an integer constant
pro:97: error: case label does not reduce to an integer constant
pro:102: error: case label does not reduce to an integer constant
pro:106: error: case label does not reduce to an integer constant
pro:110: error: case label does not reduce to an integer constant
pro:114: error: case label does not reduce to an integer constant
pro:118: error: case label does not reduce to an integer constant
pro:122: error: case label does not reduce to an integer constant
pro:126: error: case label does not reduce to an integer constant
pro:130: error: case label does not reduce to an integer constant
pro:134: error: case label does not reduce to an integer constant
pro:138: error: case label does not reduce to an integer constant
pro:142: error: case label does not reduce to an integer constant
pro:146: error: case label does not reduce to an integer constant
pro:150: error: case label does not reduce to an integer constant"

Não acha que devia publicar o código também?

o codigo é este.

#include <IRremote.h>
#include <IRremoteInt.h>

#define NUM_BUTTONS 21
int resultCode;
const uint16_t BUTTON_POWER = FD00FF;
const uint16_t BUTTON_VOLMAIS = FD807F;
const uint16_t BUTTON_STOP = FD40BF;
const uint16_t BUTTON_PTRAZ = FD20DF;
const uint16_t BUTTON_PLAY = FDA05F;
const uint16_t BUTTON_PFRENTE = FD609F;
const uint16_t BUTTON_BAIXO = FD10EF;
const uint16_t BUTTON_VOLMENOS = FD906F;
const uint16_t BUTTON_CIMA = FD50AF;
const uint16_t BUTTON_EQ = FDB04F;
const uint16_t BUTTON_ST = FD708F;
const uint16_t BUTTON_0 = FD30CF;
const uint16_t BUTTON_1 = FD08F7;
const uint16_t BUTTON_2 = FD8877;
const uint16_t BUTTON_3 = FD48B7;
const uint16_t BUTTON_4 = FD28D7;
const uint16_t BUTTON_5 = FDA857;
const uint16_t BUTTON_6 = FD6897;
const uint16_t BUTTON_7 = FD18EF;
const uint16_t BUTTON_8 = FD9867;
const uint16_t BUTTON_9 = FD58A7;

/* conectara a saída do recptor diodo IR ao pino 11*/
#define RECV_PIN 11
IRrecv irrecv(RECV_PIN);
decode_results results; // This will store our IR received codes
uint16_t lastCode = 0;

/* Configuração RGB pinos LED:*/
enum ledOrder
{
RED, // 0
GREEN, // 1
BLUE, // 2
led1, // 3
led2, // 4
led3, // 5
led4, // 6
led5, // 7
led6, // 8
led7, // 9
led8, // 10
led9, // 11
led10, // 12
led11, // 13
led12, // 14
};
const int ledPins[15] = {
22, 24, 26, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; // Vermelho, verde, azul, respectivamente pins
byte ledValues[3] = {
55, 23, 200}; //Isso mantém o controle de brilho canal
byte activeChannel = RED; // Comece com RED como o canal ativo
boolean ledEnable = 1; // Comece com o LED

void setup()
{
Serial.begin(9600); // Use série de depurar
irrecv.enableIRIn(); // Comece o receptor

/Configure os pinos de LED RGB: /
for (int i=0; i<3; i++)
{
pinMode(ledPins
, OUTPUT);

analogWrite(ledPins_, ledValues*);
}
}
void loop()
{
if (irrecv.decode(&results))
{_
uint16_t resultCode = (results.value & 0xFFFF);
_ if (resultCode == 0xFFFF)
resultCode = lastCode;
else*
* lastCode = resultCode;
}
switch (resultCode)
{_
case BUTTON_POWER:
_ Serial.println("POWER");
if (ledEnable) ledEnable = 0;
else ledEnable = 1;
break;_
case BUTTON_VOLMAIS:
_ Serial.println("VOLMAIS");
if (ledEnable) ledEnable = 0;
else ledEnable = RED;
break;_
case BUTTON_STOP:
_ Serial.println("STOP");
activeChannel = BLUE;
break;_
case BUTTON_0:
_ Serial.println("0");
activeChannel = led1;
break;_
case BUTTON_1:
_ Serial.println("1");
activeChannel = led3;
break;_
case BUTTON_2:
_ Serial.println("2");
activeChannel = led4;
break;_
case BUTTON_3:
_ Serial.println("3");
activeChannel = led4;
break;_
case BUTTON_4:
_ Serial.println("4");
activeChannel = led5;
break;_
case BUTTON_5:
_ Serial.println("5");
activeChannel = led6;
break;_
case BUTTON_6:
_ Serial.println("6");
activeChannel = led7;
break;_
case BUTTON_7:
_ Serial.println("7");
activeChannel = led8;
break;_
case BUTTON_8:
_ Serial.println("8");
activeChannel = led9;
break;_
case BUTTON_9:
_ Serial.println("9");
activeChannel = led10;
break;_
case BUTTON_VOL:
_ Serial.println("PTRAZ");
activeChannel = led11;
break;_
case BUTTON_PFRENT:
_ Serial.println("PFRENT");
activeChannel = led12;
break;*_

* default:*
* Serial.println(results.value, HEX);*
* break; *
* } *
* irrecv.resume(); // Receive the next value*
* // Every time through the loop, update the RGB LEDs:*
* if (ledEnable)*
* {*
* for (int i=0; i<3; i++)*
* {*
analogWrite(ledPins_, ledValues*);
}
}
else*

* {
for (int i=0; i<3; i++)
{
analogWrite(ledPins, 0);
}
}
}*_

Pois,era o que eu suspeitava. Estas linhas:

const uint16_t BUTTON_POWER = FD00FF;
const uint16_t BUTTON_VOLMAIS = FD807F;
const uint16_t BUTTON_STOP = FD40BF;
const uint16_t BUTTON_PTRAZ = FD20DF;
const uint16_t BUTTON_PLAY = FDA05F;
const uint16_t BUTTON_PFRENTE = FD609F;
const uint16_t BUTTON_BAIXO = FD10EF;
const uint16_t BUTTON_VOLMENOS = FD906F;
const uint16_t BUTTON_CIMA = FD50AF;
const uint16_t BUTTON_EQ = FDB04F;
const uint16_t BUTTON_ST = FD708F;
const uint16_t BUTTON_0 = FD30CF;
const uint16_t BUTTON_1 = FD08F7;
const uint16_t BUTTON_2 = FD8877;
const uint16_t BUTTON_3 = FD48B7;
const uint16_t BUTTON_4 = FD28D7;
const uint16_t BUTTON_5 = FDA857;
const uint16_t BUTTON_6 = FD6897;
const uint16_t BUTTON_7 = FD18EF;
const uint16_t BUTTON_8 = FD9867;
const uint16_t BUTTON_9 = FD58A7;

devem ser:

const uint16_t BUTTON_POWER = 0xFD00FF;
(...)

deve acrescentar '0x' a todas as linhas.

obrigado, agora ja nao da erro

é possível nesta programação meter servo motores??

Sim, tem que adicionar a biblioteca do servos e substituir a parte dos LED's RGB pelas funções do servo.

tentei fazer na pratica o código dos led's e nao esta a dar, nao sei como fazer.