Advertisement
Guest User

Untitled

a guest
May 20th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.62 KB | None | 0 0
  1. #include <MIDI.h>
  2. #include <FastLED.h>
  3.  
  4. MIDI_CREATE_DEFAULT_INSTANCE();
  5.  
  6. #define LED_PIN 12
  7. #define NUM_LEDS 110
  8. #define BRIGHTNESS 64
  9. #define LED_TYPE WS2811
  10. #define COLOR_ORDER GRB
  11.  
  12. CRGB leds[NUM_LEDS];
  13. CRGBPalette16 currentPalette;
  14. TBlendType currentBlending;
  15.  
  16. int diodes[110] =  {0, 109, 1, 108, 2, 3, 106, 4, 105, 5, 104, 6,
  17.                     7, 102, 8, 101, 9, 10, 99, 11, 98, 12, 97, 13,
  18.                     14, 95, 15, 94, 16, 17, 92, 18, 91, 19, 90, 20,
  19.                     21, 88, 22, 87, 23, 24, 85, 25, 84, 26, 83, 27,
  20.                     28, 81, 29, 80, 30, 31, 78, 32, 77, 33, 76, 34,
  21.                     35, 74, 36, 73, 37, 38, 71, 39, 70, 40, 69, 41,
  22.                     42, 67, 43, 66, 44, 45, 64, 46, 63, 47, 62, 48,
  23.                     49, 60, 50, 59, 51, 52, 57, 53, 56, 54, 55
  24.                     };
  25. void setup()
  26. {
  27.     pinMode(11, OUTPUT);
  28.     MIDI.begin();
  29.     digitalWrite(11, HIGH);
  30.     delay( 3000 ); // power-up safety delay
  31.     FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  32.     FastLED.setBrightness( BRIGHTNESS );
  33.     currentPalette = RainbowColors_p;
  34.     currentBlending = LINEARBLEND;
  35. }
  36.  
  37. void loop()
  38. {
  39.     uint8_t brightness = 120;
  40.     if (MIDI.read())
  41.     {
  42.         if (MIDI.getType()== midi::NoteOn)
  43.         {
  44.             long int i = MIDI.getData1();
  45.             if(diodes[i] < 55)
  46.                 currentPalette = CRGBPalette16(
  47.                 CRGB::White, CRGB::White, CRGB::White, CRGB::White,
  48.                 CRGB::White, CRGB::White, CRGB::White, CRGB::White,
  49.                 CRGB::White, CRGB::White, CRGB::White, CRGB::White,
  50.                 CRGB::White, CRGB::White, CRGB::White, CRGB::White
  51.                 );
  52.             else
  53.                 currentPalette = CRGBPalette16(
  54.                 CHSV( HUE_BLUE, 255, 255), CHSV( HUE_BLUE, 255, 255), CHSV( HUE_BLUE, 255, 255), CHSV( HUE_BLUE, 255, 255),
  55.                 CHSV( HUE_BLUE, 255, 255), CHSV( HUE_BLUE, 255, 255), CHSV( HUE_BLUE, 255, 255), CHSV( HUE_BLUE, 255, 255),
  56.                 CHSV( HUE_BLUE, 255, 255), CHSV( HUE_BLUE, 255, 255), CHSV( HUE_BLUE, 255, 255), CHSV( HUE_BLUE, 255, 255),
  57.                 CHSV( HUE_BLUE, 255, 255), CHSV( HUE_BLUE, 255, 255), CHSV( HUE_BLUE, 255, 255), CHSV( HUE_BLUE, 255, 255)
  58.                 );
  59.             leds[diodes[i]] = ColorFromPalette( currentPalette, 90, brightness, currentBlending);
  60.         }
  61.         if (MIDI.getType()== midi::NoteOff)
  62.         {
  63.             int i = MIDI.getData1();
  64.             leds[diodes[i]] = ColorFromPalette( currentPalette,90, 0, currentBlending);
  65.         }
  66.         FastLED.show();
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement