Paso 4: El código de Arduino
Haga clic aquí para descargar el código o copie las siguientes líneas:
#include "< \IrRemote.h\ >";
IRsend ir;
int estado = 0;
char dato;
Estos códigos son para controlar el sistema de Audio
unsigned int powerEquipo [32] = {300,750,300,1800,300,700,350,700,350,1750,350,700,300,1800,250,1800,350,700,300,1800,350,700,300,700,350,700,350,1750,300,750,300}; unsigned int chEmisoraUp [32] = {300,750,300,750,300,1750,250,800,300,750,300,750,250,800,300,750,250,1800,250,1850,300,750,250,800,200,800,300,1800,300,750,300}; unsigned int chEmisoraUp [32] = {300,750,300,750,300,1800,200,850,300,750,250,750,300,750,300,750,300,1800,300,1750,300,750,300,750,300,750,300,1800,250,750,300}; unsigned int chEmisoraDown [32] = {350,700,400,650,300,1750,350,700,350,700,350,700,300,750,300,700,350,700,300,750,350,1750,400,650,300,700,350,1750,300,750,300};
unsigned int playCd [32] = {400,650,400,650,350,1750,350,700,350,650,350,1750,350,1750,300,1750,400,1700,350,1750,350,700,350,650,400,650,350,1750,450,600,350};
Estos códigos son para el control de la Tv
unsigned int pwrTv[68]={4600,4350,700,1550,650,1550,650,1600,650,450,650,450,650,450,650,450,700,400,700,1550,650,1550,650,1600,650,450,650,450,650,450,700,450,650,450,650,450,650,1550,700,450,650,450,650,450,650,450,650,450,700,400,650,1600,650,450,650,1550,650,1600,650,1550,650,1550,700,1550,650,1550,650}; volume up unsigned int volUpTv[68]={4600,4350,650,1550,700,1500,700,1550,700,400,700,400,700,450,650,450,700,400,700,1500,700,1550,650,1550,700,400,700,400,700,450,650,450,700,400,700,1500,700,1550,650,1550,700,400,700,450,700,400,700,400,700,400,700,450,650,450,650,450,650,1550,700,1500,700,1550,700,1500,700,1550,650}; volume down unsigned int volDownTv[68]={4600,4350,700,1550,650,1550,700,1500,700,450,650,450,700,400,700,400,700,400,700,1550,700,1500,700,1550,700,400,700,400,700,400,700,450,650,450,650,1550,700,1500,700,450,650,1550,700,400,700,400,700,450,700,400,700,400,700,400,700,1550,700,400,700,1500,700,1500,700,1550,700,1500,700}; channel up unsigned int chUpTv[68]={4600,4350,700,1500,700,1500,700,1550,700,450,650,400,700,450,650,450,700,400,700,1500,700,1550,650,1550,700,450,650,450,700,400,700,400,700,400,700,400,700,1550,700,400,700,400,700,1550,650,450,700,400,700,400,700,1550,650,450,650,1600,650,1550,650,450,700,1500,700,1500,700,1550,650}; channel down unsigned int chDownTv[68]={4650,4300,700,1550,700,1500,700,1550,700,400,700,400,700,400,700,450,650,450,650,1550,700,1500,700,1550,700,400,700,400,700,400,700,450,700,400,700,400,700,400,700,450,650,450,650,1550,700,400,700,450,650,400,700,1550,700,1500,700,1550,700,1500,700,400,700,1550,650,1550,700,1500,700};
Tv/Video unsigned int videoTv[68]={4500,4300,650,1600,650,1550,650,1600,650,500,600,500,650,500,650,500,650,500,600,1650,600,1600,650,1550,650,500,650,500,650,500,600,500,650,500,650,1600,600,500,650,500,650,500,650,500,600,550,600,500,650,500,650,500,650,1550,650,1600,650,1550,650,1600,650,1550,650,1600,650,1550,650};
void setup()
{
Serial.Begin(9600);
}
void loop()
{
if(serial.Available() > 0)
{dato=Serial.read();
interruptor (dato)
{'R' del caso:
ir.sendRaw(powerEquipo,32,38);
Delay(500);
rotura;
caso ' t ':
ir.sendRaw(chEmisoraUp,32,38);
Delay(100);
rotura;
caso 'U':
ir.sendRaw(chEmisoraDown,32,38);
Delay(100);
rotura;
caso 'V':
ir.sendRaw(playCd,32,38);
Delay(100);
rotura;
caso 'K':
Poder de la TV
ir.sendRaw(pwrTv,68,38);
Delay(100);
rotura;
caso 'L':
Volumen +
ir.sendRaw(volUpTv,68,38);
Delay(100);
rotura;
caso soy ':
Volumen-
ir.sendRaw(volDownTv,68,38);
Delay(100);
rotura;
caso ' n ':
Canal +
ir.sendRaw(chUpTv,68,38);
Delay(100);
rotura;
caso ' o ':
Canal-
ir.sendRaw(chDownTv,68,38);
Delay(100);
rotura;
caso 'P':
TV/Video
ir.sendRaw(videoTv,68,38);
Delay(100);
rotura;
caso 'A':
para (int i = 0; i < 3; i ++)
{
ir.sendNEC (0xFF30CF, 32); Power DVD
Delay(40);
}
rotura;
caso 'B':
para (int i = 0; i < 3; i ++)
{
ir.sendNEC (0xFF00FF, 32); /Close abierto
Delay(40);
}
rotura;
caso 'C':
para (int i = 0; i < 3; i ++)
{
ir.sendNEC (0xFF52AD, 32); Juego
Delay(40);
}
rotura;
caso sería ':
para (int i = 0; i < 3; i ++)
{
ir.sendNEC (0xFF728D, 32); Parada
Delay(40);
} break;
} / / fin del interruptor
} //fin del si
} //fin del bucle