Hi, found the below code and attempted to apply it. I contacted Lutron and they sent me the following specs:
IR carrier Frequency 40.0 kHz
Duty Cycle 40%
Baud Rate 437 bps
Bit on time 10 usec, off time 15 usec
When I run the scrip the up command is processed about 30% of the time. So I assume much of the code is correct, but the processing by the dimmer is inconsistent. I suspect perhaps the baud rate but not sure how to set it or perhaps the duty cycle. I changed the pulse width from 2300 to 2200 and processing improved about 15%. Any other thoughts on how to proceed etc?
Thanks in advance
_Ernie
/* Control a Lutron Maestro light dimmer */
#define BIT_IS_SET(i, bits) (1 << i & bits)
// LED connected to digital pin 4
const int LED_PIN = 4;
// Width of a pulse, in microseconds 2200 is better than 2300
const int PULSE_WIDTH = 2200;
// # of bytes per command
const int COMMAND_LENGTH = 4;
const int UP[] = {255, 136, 130, 34};
const int DOWN[] = {255, 136, 130, 20};
const int ON[] = {255, 136, 132, 184};
const int OFF[] = {255, 136, 189, 18};
const int RECALL[] = {255, 136, 132, 183};
void setup()
{
pinMode(LED_PIN, OUTPUT);
}
/* Modulate pin at 39 kHz for give number of microseconds */
void on(int pin, int time) {
static const int period = 25;
// found wait_time by measuring with oscilloscope
static const int wait_time = 9;
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 byte over the IR LED */
void send_byte(int bits) {
for (int i = 7; 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(const int bytes[]) {
for (int i = 0; i < COMMAND_LENGTH; i++) {
send_byte(bytes);*
- }*
off(LED_PIN, 4 * PULSE_WIDTH);
}
void loop()
{ - command(UP);*
- delay(2000);*
}