Yaros_

Arduino Underlights

Jun 12th, 2021
132
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const byte _nLED = 60;  // Number of LEDs in your underlights device
  2. const byte _dLED = 4;   // DIN Pin (PIN 4 is recommended)
  3.  
  4. #include <Adafruit_NeoPixel.h>
  5. Adafruit_NeoPixel _LED = Adafruit_NeoPixel(_nLED, _dLED, NEO_GRB + NEO_KHZ800);
  6.  
  7. // NOVATION'S PALLETE
  8.  
  9. const byte _r[128] = {0, 28, 125, 255, 255, 255, 85, 24, 255, 255, 85, 36, 255, 255, 85, 24, 134, 81, 28, 16, 73, 0, 0, 0, 73, 0, 0, 0, 73, 0, 0, 0, 73, 0, 0, 0, 73, 0, 0, 0, 73, 0, 0, 0, 73, 0, 0, 0, 134, 81, 24, 12, 255, 255, 85, 24, 255, 255, 85, 32, 255, 150, 117, 65, 0, 0, 0, 0, 0, 36, 125, 28, 255, 186, 174, 97, 12, 0, 0, 0, 61, 121, 174, 61, 255, 134, 113, 0, 57, 85, 53, 89, 49, 134, 210, 255, 255, 182, 142, 130, 57, 16, 12, 20, 20, 101, 166, 219, 215, 255, 158, 101, 28, 219, 125, 154, 142, 61, 113, 223, 158, 53, 24, 4, 182, 61, 178, 73};
  10. const byte _g[128] = {0, 28, 125, 255, 73, 0, 0, 0, 186, 81, 28, 24, 255, 255, 85, 24, 255, 255, 85, 40, 255, 255, 85, 24, 255, 255, 85, 24, 255, 255, 85, 28, 255, 255, 85, 24, 194, 166, 65, 12, 134, 85, 28, 4, 73, 0, 0, 0, 73, 0, 0, 0, 73, 0, 0, 0, 73, 0, 0, 0, 20, 53, 81, 97, 57, 85, 81, 0, 69, 0, 125, 28, 0, 255, 235, 255, 138, 255, 166, 40, 0, 0, 24, 32, 73, 223, 255, 255, 255, 255, 255, 138, 81, 125, 28, 0, 125, 174, 255, 89, 40, 73, 77, 20, 28, 57, 0, 81, 105, 223, 223, 178, 28, 255, 255, 150, 101, 61, 113, 255, 0, 0, 206, 65, 174, 49, 93, 20};
  11. const byte _b[128] = {0, 28, 125, 255, 73, 0, 0, 0, 105, 0, 0, 0, 73, 0, 0, 0, 73, 0, 0, 0, 73, 0, 0, 0, 93, 24, 12, 0, 134, 85, 28, 16, 182, 150, 53, 16, 255, 255, 81, 24, 255, 255, 85, 24, 255, 255, 85, 24, 255, 255, 97, 45, 255, 255, 85, 24, 134, 81, 28, 16, 0, 0, 0, 0, 0, 53, 125, 255, 77, 202, 125, 28, 0, 45, 4, 8, 0, 134, 255, 255, 255, 255, 121, 0, 0, 4, 20, 0, 36, 109, 202, 255, 194, 231, 255, 89, 0, 0, 0, 4, 0, 12, 53, 40, 89, 24, 8, 61, 24, 36, 45, 12, 45, 105, 186, 255, 255, 61, 113, 255, 0, 0, 0, 0, 0, 0, 0, 0};
  12.  
  13.  
  14. const byte _pStart = 36;  // First note in array
  15. bool update = false;
  16.  
  17. void noteOn(byte ch, byte p, byte v) {
  18.   _LED.setPixelColor(p - _pStart, _r[v], _g[v], _b[v]);
  19.   update = true;
  20. }
  21.  
  22. void noteOff(byte ch, byte p, byte v) {
  23.   _LED.setPixelColor(p - _pStart, 0, 0, 0);
  24.   update = true;
  25. }
  26.  
  27. void sysEx(byte *data, unsigned int length) {
  28.   if (length == 6) {
  29.     _LED.setPixelColor(*(data+1) - _pStart, *(data+2), *(data+3), *(data+4));
  30.     update = true;
  31.   }
  32. }
  33.  
  34. void setup() {
  35.   _LED.begin();
  36.   _LED.show();
  37.  
  38.   usbMIDI.setHandleNoteOn(noteOn);
  39.   usbMIDI.setHandleNoteOff(noteOff);
  40.   usbMIDI.setHandleSystemExclusive(sysEx);
  41. }
  42.  
  43. void loop() {
  44.   while (usbMIDI.read());
  45.   if (update) {
  46.     _LED.show();
  47.     update = false;
  48.   }
  49. }
RAW Paste Data