Paso 4: El código en Arduino
Copie las siguientes líneas o descargue el código desde aca y carguelo Arduino.
#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}; These codes are for controlling the 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)
{
caso 'R':
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': //Power la TV
ir.sendRaw(pwrTv,68,38);
Delay(100);
rotura;
caso 'L': //Volume +
ir.sendRaw(volUpTv,68,38);
Delay(100);
rotura; caso soy ': /
/ Volumen-
ir.sendRaw(volDownTv,68,38);
Delay(100);
rotura;
caso ' n ': //Channel +
ir.sendRaw(chUpTv,68,38);
Delay(100);
rotura;
caso ' o ': //Channel -
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); Abrir/cerrar bandeja cd
Delay(40);
}
rotura;
caso 'C':
para (int i = 0; i < 3; i ++)
{
ir.sendNEC (0xFF52AD, 32); Reproducir cd
Delay(40);
}
rotura;
caso sería ':
para (int i = 0; i < 3; i ++)
{
ir.sendNEC (0xFF728D, 32); Parada
Delay(40);
}
rotura;
} / / fin del interruptor}
fin del si
} //fin del bucle