Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Created by DIYables
- This example code is in the public domain
- Product page: https://diyables.io/products/infrared-ir-remote-control-kit-with-17-key-controller-and-receiver
- */
- #include <DIYables_IRcontroller.h> // DIYables_IRcontroller library
- #define IR_RECEIVER_PIN 8 // The Arduino pin connected to IR controller
- int RLed = 9;
- int GLed = 10;
- int BLed = 11;
- DIYables_IRcontroller_17 irController(IR_RECEIVER_PIN, 200); // debounce time is 200ms
- void setup() {
- Serial.begin(9600);
- irController.begin();
- pinMode(RLed, OUTPUT);
- pinMode(GLed, OUTPUT);
- pinMode(BLed, OUTPUT);
- }
- void loop() {
- Key17 command = irController.getKey();
- if (command != Key17::NONE) {
- switch (command) {
- case Key17::KEY_1:
- Serial.println("Red");
- setColor(255, 0, 0); // Red
- break;
- case Key17::KEY_2:
- Serial.println("Green");
- setColor(0, 255, 0); // Green
- break;
- case Key17::KEY_3:
- Serial.println("Blue");
- setColor(0, 0, 255); // Blue
- break;
- case Key17::KEY_4:
- Serial.println("Yellow");
- setColor(255, 255, 0); // Yellow
- break;
- case Key17::KEY_5:
- Serial.println("Cyan");
- setColor(0, 255, 255); // Cyan
- break;
- case Key17::KEY_6:
- Serial.println("Magenta");
- setColor(255, 0, 255); // Magenta
- break;
- case Key17::KEY_7:
- Serial.println("White");
- setColor(255, 255, 255); // White
- break;
- case Key17::KEY_8:
- Serial.println("Off");
- setColor(0, 0, 0); // Off
- break;
- case Key17::KEY_9:
- Serial.println("Blinking Red");
- blinkColor(255, 0, 0); // Blinking Red
- break;
- case Key17::KEY_STAR:
- Serial.println("Blinking Green");
- blinkColor(0, 255, 0); // Blinking Green
- break;
- case Key17::KEY_0:
- Serial.println("Blinking Blue");
- blinkColor(0, 0, 255); // Blinking Blue
- break;
- case Key17::KEY_SHARP:
- Serial.println("Blinking White");
- blinkColor(255, 255, 255); // Blinking White
- break;
- case Key17::KEY_UP:
- Serial.println("Brightness Up");
- adjustBrightness(10); // Increase brightness
- break;
- case Key17::KEY_DOWN:
- Serial.println("Brightness Down");
- adjustBrightness(-10); // Decrease brightness
- break;
- case Key17::KEY_LEFT:
- Serial.println("Cycle Colors");
- cycleColors(); // Cycle through colors
- break;
- case Key17::KEY_RIGHT:
- Serial.println("Rainbow");
- rainbowCycle(); // Rainbow effect
- break;
- case Key17::KEY_OK :
- Serial.println("Reset");
- reset(); // Reset to default state
- break;
- default:
- Serial.println("WARNING: undefined command:");
- break;
- }
- }
- }
- void setColor(int r, int g, int b) {
- analogWrite(RLed, r);
- analogWrite(GLed, g);
- analogWrite(BLed, b);
- }
- void blinkColor(int r, int g, int b) {
- for (int i = 0; i < 5; i++) { // Blink 5 times
- setColor(r, g, b);
- delay(500);
- setColor(0, 0, 0);
- delay(500);
- }
- }
- void adjustBrightness(int adjustment) {
- static int brightness = 255; // Initial brightness
- brightness = constrain(brightness + adjustment, 0, 255);
- analogWrite(RLed, brightness);
- analogWrite(GLed, brightness);
- analogWrite(BLed, brightness);
- }
- void cycleColors() {
- setColor(255, 0, 0); delay(1000);
- setColor(0, 255, 0); delay(1000);
- setColor(0, 0, 255); delay(1000);
- setColor(255, 255, 0); delay(1000);
- setColor(0, 255, 255); delay(1000);
- setColor(255, 0, 255); delay(1000);
- }
- void rainbowCycle() {
- for (int j = 0; j < 256; j++) { // 1 cycle of all 256 colors in the wheel
- for (int i = 0; i < 3; i++) {
- setColor((255 - i * 85 + j) % 255, (i * 85 + j) % 255, (255 - j) % 255);
- delay(10);
- }
- }
- }
- void reset() {
- setColor(0, 0, 0); // Turn off LED
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement