#include <Bounce2.h>
#include <IRremote.h>
IRsend irsend;//ir led in pin D3
#define pin1 11 //rotary encoder for channel
#define pin2 12 //rotary encoder for channel
#define pin4 9 //rotary encode for volume
#define pin3 10 //rotary encode for volume
#define pushbutoon 4 //pushbutton for on off
int khz=38; //frequency for ir send
//TV ON/OFF
unsigned int Signal_0_0[] = {4550,4400,600,1650,550,1650,600,1650,550,550,600,500,600,550,550,550,600,500,600,1650,600,1600,600,1650,550,550,600,500,600,550,600,500,600,500,650,450,650,1600,600,500,650,450,650,500,600,500,600,500,600,550,600,1600,600,500,650,1600,650,1550,650,1600,650,1550,650,1600,650,1600,600}; //AnalysIR Batch Export - RAW
// volume up
const unsigned int S_vup[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
const unsigned int S_vdown[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};
// Instantiate a Bounce objects
Bounce bouncer1 = Bounce( ); //channel
Bounce bouncer2 = Bounce( ); //volume
Bounce bouncer3 = Bounce( ); //on-off
void setup() {
pinMode(pin1,INPUT);
bouncer1 .attach( pin1 );
bouncer1 .interval(5);
pinMode(pin2,INPUT);
pinMode(pin1,INPUT);
bouncer2 .attach( pin3 );
bouncer2 .interval(5);
pinMode(pin2,INPUT);
bouncer3 .attach( pushbutoon );
bouncer3 .interval(5);
Serial.begin(9600);
}
void loop() {
// Update the debouncer
bouncer1.update ( );
bouncer2.update ( );
bouncer3.update ( );
// Turn on or off the LED and
// increment or decrement the counter
if ( bouncer1.risingEdge()) {
if (digitalRead(pin2)){
Serial.println("CHANNEL UP");
irsend.sendNEC(0xC0C8C73, 32);
}else{
Serial.println("CHANNEL DOWN");
irsend.sendNEC(0xC0C0CF3, 32);
}
}
if ( bouncer2.risingEdge()) {
if (digitalRead(pin4)){
for (int i = 0; i < 3; i++) {
irsend.sendRaw(S_vup, sizeof(S_vup)/sizeof(int), khz); //AnalysIR Batch Export - RAW delay(40);
delay(20);
}
Serial.println("Volume UP");
}else{
for (int i = 0; i < 3; i++) {
irsend.sendRaw(S_vdown, sizeof(S_vdown)/sizeof(int), khz); //AnalysIR Batch Export - RAW delay(40);
delay(20);
}
Serial.println("Volume DOWN");
}
}
if ( bouncer3.risingEdge()) {
if (digitalRead(pushbutoon)){
for (int i = 0; i < 3; i++) {
irsend.sendRaw(Signal_0_0, sizeof(Signal_0_0)/sizeof(int), khz);
delay(40);
}
Serial.println("On OFF");
}
}
}
Comments