99 lines
3.1 KiB
Arduino
99 lines
3.1 KiB
Arduino
|
#include <IRremote.h>
|
||
|
|
||
|
#define LED_WHITE 6
|
||
|
#define LED_GREEN 9
|
||
|
#define LED_BLUE 10
|
||
|
#define LED_RED 11
|
||
|
|
||
|
#define IR_PIN 8
|
||
|
#define IR_PROTOCOL 1
|
||
|
#define IR_FILTER 0xF70000
|
||
|
#define IR_MASK 0xFF0000
|
||
|
#define IR_KEY_1 0xF720DF
|
||
|
#define IR_KEY_2 0xF710EF
|
||
|
#define IR_KEY_3 0xF730CF
|
||
|
#define IR_KEY_4 0xF70000 // key is broken :-(
|
||
|
#define IR_KEY_5 0xF728D7
|
||
|
#define IR_KEY_6 0xF7A05F
|
||
|
#define IR_KEY_7 0xF7906F
|
||
|
#define IR_KEY_8 0xF7B04F
|
||
|
#define IR_KEY_9 0xF78877
|
||
|
#define IR_KEY_FLASH 0xF7D02F
|
||
|
#define IR_KEY_STROBE 0xF7F00F
|
||
|
#define IR_KEY_FADE 0xF7C837
|
||
|
#define IR_KEY_SMOOTH 0xF7E817
|
||
|
#define IR_KEY_DIM 0xF7807F
|
||
|
#define IR_KEY_BRIGHT 0xF700FF
|
||
|
#define IR_KEY_ALLON 0xF7C03F
|
||
|
#define IR_KEY_ALLOFF 0xF740BF
|
||
|
#define IR_KEY_LIGHT10 0xF7A857
|
||
|
#define IR_KEY_LIGHT11 0xF7609F
|
||
|
#define IR_KEY_LIGHT12 0xF750AF
|
||
|
#define IR_KEY_LIGHT13 0xF7708F
|
||
|
#define IR_KEY_LIGHT14 0xF748B7
|
||
|
#define IR_KEY_LIGHT15 0xF76897
|
||
|
#define IR_KEY_LIGHT16 0xF7E01F
|
||
|
|
||
|
int leds[] = {LED_WHITE, LED_GREEN, LED_BLUE, LED_RED};
|
||
|
int white = 0x80;
|
||
|
|
||
|
IRrecv irrecv(IR_PIN);
|
||
|
decode_results results;
|
||
|
|
||
|
void setup() {
|
||
|
for (int i = 0; i < 4; i++) {
|
||
|
pinMode(leds[i], OUTPUT);
|
||
|
analogWrite(leds[i], 0x00);
|
||
|
}
|
||
|
analogWrite(LED_WHITE, white);
|
||
|
Serial.begin(9600);
|
||
|
irrecv.enableIRIn(); // Start the receiver
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
if (irrecv.decode(&results)) {
|
||
|
if (results.decode_type == IR_PROTOCOL) {
|
||
|
if (results.value != 0xFFFFFFFF) {
|
||
|
//if (results.value & IR_MASK == IR_FILTER) {
|
||
|
switch (results.value) {
|
||
|
case IR_KEY_1: Serial.println("key 1"); analogWrite(LED_RED, 0x00); break;
|
||
|
case IR_KEY_2: Serial.println("key 2"); analogWrite(LED_GREEN, 0x00); break;
|
||
|
case IR_KEY_3: Serial.println("key 3"); analogWrite(LED_BLUE, 0x00); break;
|
||
|
case IR_KEY_4: Serial.println("key 4"); analogWrite(LED_RED, 0x80); break;
|
||
|
case IR_KEY_5: Serial.println("key 5"); analogWrite(LED_GREEN, 0x80); break;
|
||
|
case IR_KEY_6: Serial.println("key 6"); analogWrite(LED_BLUE, 0x80); break;
|
||
|
case IR_KEY_7: Serial.println("key 7"); analogWrite(LED_RED, 0xFF); break;
|
||
|
case IR_KEY_8: Serial.println("key 8"); analogWrite(LED_GREEN, 0xFF); break;
|
||
|
case IR_KEY_9: Serial.println("key 9"); analogWrite(LED_BLUE, 0xFF); break;
|
||
|
case IR_KEY_DIM:
|
||
|
white -= 0x10;
|
||
|
if (white < 0x00) {
|
||
|
white = 0x00;
|
||
|
}
|
||
|
Serial.print("-white: ");
|
||
|
Serial.println(white, HEX);
|
||
|
analogWrite(LED_WHITE, white);
|
||
|
break;
|
||
|
case IR_KEY_BRIGHT:
|
||
|
white += 0x10;
|
||
|
if (white > 0xFF) {
|
||
|
white = 0xFF;
|
||
|
}
|
||
|
Serial.print("+white: ");
|
||
|
Serial.println(white, HEX);
|
||
|
analogWrite(LED_WHITE, white);
|
||
|
break;
|
||
|
default:
|
||
|
Serial.print("proto: ");
|
||
|
Serial.print(results.decode_type, DEC);
|
||
|
Serial.print(" code: ");
|
||
|
Serial.println(results.value, HEX);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
irrecv.resume(); // Receive the next value
|
||
|
}
|
||
|
}
|
||
|
|