hie to everyone ,
I am a beginer about Arduino and i would like some help .
I want to make a TV remote using an Arduino and IR led.
I would like to program it in order to send messages to the TV for making change the channel randomly every second ( channel 1 to the 6 ) .
I have try something but it doesn't work and i don't have enough knowledge about RC5 codes.
the code :
/* Control a Lutron Maestro light dimmer */
#define BIT_IS_SET(i, bits) (1 << i & bits)
// LED connected to digital pin 13
const int LED_PIN = 13;
// Width of a pulse, in microseconds
const int PULSE_WIDTH = 1778; // 2300; // TV= 1778
// TV adressage
const int TV_ADRESS=13; // 5BITS - EX. SONY= =13
// INSTRUCTION VAR
int INSTRUCTION=0;
void setup(){
pinMode(LED_PIN, OUTPUT);
}
//1hz = 1000 miliseconds
//3.9khz =3900 millis
//
/* Modulate pin at 39 kHz for give number of microseconds */
//tv = 36Khz
// THIS FUNCTION SOMEHOW HAS TO BE ADJUSTED
void on(int pin, int time) {// time=pulse_width =1778 for tv
static const int period = 25;
static const int wait_time = 9; //adjust by hand!?
for (time = time/period; time > 0; time--) {
digitalWrite(pin, HIGH);
delayMicroseconds(wait_time);
digitalWrite(pin, LOW);
delayMicroseconds(wait_time);
}
}
/* Leave pin off for time (given in microseconds) /
void off(int pin, int time) {
digitalWrite(pin, LOW);
delayMicroseconds(time);
}
/ Send a start code over the IR LED /
void send_byte_depart() { // 1 byte= 8bits
on(LED_PIN, PULSE_WIDTH);
on(LED_PIN, PULSE_WIDTH);
}
/ Send change key over the IR LED /
void send_byte_basculement() { // 1 byte= 8bits
on(LED_PIN, PULSE_WIDTH);
}
/ Send brand code over the IR LED */
void send_byte_adressage(int bits) { // 1 byte= 8bits
for (int i = 4; i >= 0; i--){
if (BIT_IS_SET(i, bits)) {
on(LED_PIN, PULSE_WIDTH);
}else {
off(LED_PIN, PULSE_WIDTH);
}
}
}
/* Send instruction code over the IR LED */
void send_byte_instruction(int bits) {
for (int i = 5; i >= 0; i--){
if (BIT_IS_SET(i, bits)) {
on(LED_PIN, PULSE_WIDTH);
}else {
off(LED_PIN, PULSE_WIDTH);
}
}
}
/* Send a full command */
void command(int instruction) {
send_byte_depart();
send_byte_basculement();
send_byte_adressage(TV_ADRESS);
send_byte_instruction(instruction); // EX= IF key 6 | INSTRUCTION=6
}
void loop(){
INSTRUCTION=int(random(1,7)); // between 1 and 6
command(INSTRUCTION);
delay(1000);
}
Sorry for my bad english .
Thank you for your help