Advertisement
atuline

IRLTest with rainbow

Aug 30th, 2019
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.44 KB | None | 0 0
  1. /* irltest with rainbow
  2.  *
  3.  * By: Andrew Tuline
  4.  *
  5.  * Date: Nov, 2014
  6.  *
  7.  * Updated: May, 2019
  8.  *
  9.  * TEST program for IRLRemote and FastLED to ensure they work together with the strip you're using. It's also a good routine to test IR keyboard mapping.
  10.  *
  11.  * I'm using the TSOP38238 IR receiver with an el cheapo aliexpress IR transmitter.
  12.  *
  13.  * Libraries required:
  14.  *
  15.  * https://github.com/NicoHood/IRLremote
  16.  * https://github.com/FastLED/FastLED
  17.  *
  18.  * Note: 3 pin LED strips such as WS2812B running FastLED won't work with this or with Ken Shiriff's IR library.
  19.  *
  20.  */
  21.  
  22.  
  23.  
  24. #include "FastLED.h"                                          // https://github.com/FastLED/FastLED     Use 3.2
  25. #include "IRLremote.h"                                        // https://github.com/NicoHood/IRLremote  Use 2.0.2
  26.  
  27. #include "commands.h"                                         // The IR commands.
  28.  
  29. #if IRL_VERSION < 202
  30. #error "Requires IRLRemote 2.0.2 or later; check github for latest code."
  31. #endif
  32.  
  33. #if FASTLED_VERSION < 3001000
  34. #error "Requires FastLED 3.1 or later; check github for latest code."
  35. #endif
  36.  
  37. // choose a valid PinInterrupt pin of your Arduino board
  38. #define pinIR 2                                               // I'm using pin D2
  39. #define IRL_BLOCKING true
  40.  
  41. CNec IRLremote;
  42.  
  43. uint8_t gHue = 0;
  44.  
  45. // Fixed definitions cannot change on the fly.
  46. #define LED_DT 12                                             // Data pin to connect to the strip.
  47. #define LED_CK 11                                             // Clock pin for WS2801 or APA102.
  48. #define COLOR_ORDER BGR                                       // It's GRB for WS2812 and BGR for APA102.
  49. #define LED_TYPE APA102                                       // Using APA102, WS2812, WS2801. Don't forget to modify LEDS.addLeds to suit.
  50. #define NUM_LEDS 30                                           // Number of LED's.
  51.  
  52. struct CRGB leds[NUM_LEDS];
  53.  
  54. // Global variables can be changed on the fly.
  55. uint8_t max_bright = 128;                                      // Overall brightness.
  56.  
  57.  
  58.  
  59. void setup() {
  60.  
  61.   Serial.begin(115200);                                        // Initialize serial port for debugging.
  62.  
  63.   delay(1000);                                                // Soft startup to ease the flow of electrons.
  64.  
  65.   if (!IRLremote.begin(pinIR))
  66.     Serial.println(F("You did not choose a valid pin."));
  67.  
  68. //  LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);      // For WS2812B - Does not work due to 3 pin configuration.
  69.   LEDS.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS);   // For APA102 or WS2801
  70.  
  71.   FastLED.setBrightness(max_bright);
  72.  
  73.   set_max_power_in_volts_and_milliamps(5, 500);               // FastLED Power management set at 5V, 500mA.
  74.  
  75. } // setup()
  76.  
  77.  
  78.  
  79. void loop() {
  80.  
  81.   EVERY_N_MILLISECONDS(20) {gHue++;}  
  82.  
  83.       if (!IRLremote.receiving()) {
  84.  
  85.         FastLED.show();                                                             // Power managed display of LED's.
  86.         FastLED.delay(10);
  87.       }
  88.  
  89.       fill_rainbow(leds,NUM_LEDS,gHue, 10);
  90.        
  91.   irltest();
  92.  
  93. } // loop()
  94.  
  95.  
  96.  
  97. void irltest() {                                      // This is the built-in IR function that just selects a mode.
  98.  
  99.  
  100.   if (IRLremote.available()) {
  101.    
  102.     auto data = IRLremote.read();           // Get the new data from the remote
  103.  
  104. //    Serial.print(F("Address: "));           // Print the protocol data. Note that there's also 65535, which we don't use.
  105. //    Serial.println(data.address);
  106. //    Serial.print(F("Command: "));
  107. //    Serial.println(data.command);
  108. //    Serial.println();
  109.  
  110.     if (data.address == IR_ADD) {    
  111.       switch(data.command) {
  112.  
  113.       case IR_A1:  change_mode(1);   break;          //a1 -
  114.       case IR_A2:  change_mode(2);   break;          //a2 -
  115.       case IR_A3:  change_mode(3);   break;          //a3 -
  116.       case IR_A4:  change_mode(4);   break;          //a4 -
  117.  
  118.       case IR_B1:  change_mode(5);   break;          //b1 -
  119.       case IR_B2:  change_mode(6);   break;          //b2 -
  120.       case IR_B3:  change_mode(7);   break;          //b3 -
  121.       case IR_B4:  change_mode(8);   break;          //b4 -
  122.  
  123.       case IR_C1:  change_mode(9);   break;          //c1 -
  124.       case IR_C2:  change_mode(10);  break;          //c2 -
  125.       case IR_C3:  change_mode(11);  break;          //c3 -
  126.       case IR_C4:  change_mode(12);  break;          //c4 -
  127.  
  128.       case IR_D1:  change_mode(13);  break;          //d1 -
  129.       case IR_D2:  change_mode(14);  break;          //d2 -
  130.       case IR_D3:  change_mode(15);  break;          //d3 -
  131.       case IR_D4:  change_mode(16);  break;          //d4 -
  132.  
  133.       case IR_E1:  change_mode(17);  break;          //e1 -
  134.       case IR_E2:  change_mode(18);  break;          //e2 -
  135.       case IR_E3:  change_mode(19);  break;          //e3 -
  136.       case IR_E4:  change_mode(20);  break;          //e4 -
  137.  
  138.       case IR_F1:  change_mode(21);  break;          //f1 -
  139.       case IR_F2:  change_mode(22);  break;          //f2 -
  140.       case IR_F3:  change_mode(98);  break;          //f3 -
  141.       case IR_F4:  change_mode(99);  break;          //f4 -
  142.  
  143.       default: break;                                // We could do something by default
  144.      
  145.       } // switch IRCommand
  146.     } // if IR_ADD
  147.   } // if IRLRemote
  148.  
  149.  
  150. } // irltest()
  151.  
  152.  
  153.  
  154. void change_mode(int newmode) {
  155.  
  156.   Serial.print("New mode: ");
  157.   Serial.println(newmode);
  158.  
  159. } // change_mode()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement