#include "FastLED.h" #define NUM_LEDS 5 // 5 #define DATA_PIN 6 // 6- DIN ( ) // CRGB leds[NUM_LEDS]; void setup() { FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // } void loop() { FastLED.showColor(CHSV(190,255,255)); // }
// MIDI Wavy // JVLNS.ORG 2014 // #include "FastLED.h" // , #define LEFT_LONG 7 #define LEFT_SHORT 6 #define RIGHT_SHORT 5 #define RIGHT_LONG 4 #define NUM_STRIPS 4 // #define NUM_LEDS_PER_STRIP 5 // 1 // CRGB leds[NUM_STRIPS][NUM_LEDS_PER_STRIP]; // , byte colors[] = {0, 32, 64, 96, 128, 160, 192, 224, 239 }; // Master () - byte ColorBasic = 0; byte Master = 255; byte commandByte; // MIDI-, (noteOn, noteOff, Controller) byte noteByte; // ( ) byte velocityByte; // — ( noteOn/Off velocity (https://www.ableton.com/en/manual/editing-midi-notes-and-velocities), Controller — ). byte velocityByte1; // map() 0-127 0-255 byte noteOn = 144; // byte noteOff = 128; // byte faza = 0; // delay(faza)
void setup() { // Serial- 256000 Serial.begin(256000); FastLED.addLeds<NEOPIXEL, LEFT_LONG>(leds[0], NUM_LEDS_PER_STRIP); FastLED.addLeds<NEOPIXEL, LEFT_SHORT>(leds[1], NUM_LEDS_PER_STRIP); FastLED.addLeds<NEOPIXEL, RIGHT_SHORT>(leds[2], NUM_LEDS_PER_STRIP); FastLED.addLeds<NEOPIXEL, RIGHT_LONG>(leds[3], NUM_LEDS_PER_STRIP); }
// pointer() // num_strip = ( 0 3, [ ]) // num_led = num_strip // master = // color = void pointer(byte num_strip, byte num_led, byte master, byte color) { leds[num_strip][num_led] = CHSV(color, 255, master); FastLED.show(); } // blackout() void blackout(byte num_strip, byte num_led) { leds[num_strip][num_led] = CHSV(0, 0, 0); FastLED.show(); }
void checkMIDI(){ do{ // 3 if (Serial.available()){ commandByte = Serial.read();//read first byte noteByte = Serial.read();//read next byte velocityByte1 = Serial.read();//read final byte velocityByte = map(velocityByte1, 0, 127, 0, 255); Master = velocityByte; // Master Velocity // if(noteByte == 96) ColorBasic = colors[0]; if(noteByte == 97) ColorBasic = colors[1]; if(noteByte == 98) ColorBasic = colors[2]; if(noteByte == 99) ColorBasic = colors[3]; if(noteByte == 100) ColorBasic = colors[4]; if(noteByte == 101) ColorBasic = colors[5]; if(noteByte == 102) ColorBasic = colors[6]; if(noteByte == 103) ColorBasic = colors[7]; if(noteByte == 104) ColorBasic = colors[8]; // if (commandByte == 176 && noteByte == 22)ColorBasic = velocityByte; // Color if(commandByte == 176 && noteByte == 21) Master = velocityByte; // Master if(commandByte == 176 && noteByte == 23) faza = velocityByte; // Velocity // LEFT_LONG if(noteByte == 36) { //C1 if(commandByte == noteOn) pointer(0, 0, Master, ColorBasic); else if(commandByte == noteOff) blackout(0, 0); } if(noteByte == 38) { if(commandByte == noteOn) pointer(0, 1, Master, ColorBasic); else if(commandByte == noteOff) blackout(0, 1); } if(noteByte == 40) { if(commandByte == noteOn) pointer(0, 2, Master, ColorBasic); else if(commandByte == noteOff) blackout(0, 2); } if(noteByte == 41) { if(commandByte == noteOn) pointer(0, 3, Master, ColorBasic); else if(commandByte == noteOff) blackout(0, 3); } if(noteByte == 43) { if(commandByte == noteOn) pointer(0, 4, Master, ColorBasic); else if(commandByte == noteOff) blackout(0, 4); } // end left_long // LEFT_SHORT if(noteByte == 45) { if(commandByte == noteOn) pointer(1, 0, Master, ColorBasic); else if(commandByte == noteOff) blackout(1, 0); } if(noteByte == 47) { if(commandByte == noteOn) pointer(1, 1, Master, ColorBasic); else if(commandByte == noteOff) blackout(1, 1); } if(noteByte == 48) { if(commandByte == noteOn) pointer(1, 2, Master, ColorBasic); else if(commandByte == noteOff) blackout(1, 2); } if(noteByte == 50) { if(commandByte == noteOn) pointer(1, 3, Master, ColorBasic); else if(commandByte == noteOff) blackout(1, 3); } if(noteByte == 52) { if(commandByte == noteOn) pointer(1, 4, Master, ColorBasic); else if(commandByte == noteOff) blackout(1, 4); } // end left_short // RIGHT_SHORT if(noteByte == 53) { if(commandByte == noteOn) pointer(2, 0, Master, ColorBasic); else if(commandByte == noteOff) blackout(2, 0); } if(noteByte == 55) { if(commandByte == noteOn) pointer(2, 1, Master, ColorBasic); else if(commandByte == noteOff) blackout(2, 1); } if(noteByte == 57) { if(commandByte == noteOn) pointer(2, 2, Master, ColorBasic); else if(commandByte == noteOff) blackout(2, 2); } if(noteByte == 59) { if(commandByte == noteOn) pointer(2, 3, Master, ColorBasic); else if(commandByte == noteOff) blackout(2, 3); } if(noteByte == 60) { if(commandByte == noteOn) pointer(2, 4, Master, ColorBasic); else if(commandByte == noteOff) blackout(2, 4); } // end right_short // RIGHT_LONG if(noteByte == 62) if(commandByte == noteOn) pointer(3, 0, Master, ColorBasic); else if(commandByte == noteOff) blackout(3, 0); } if(noteByte == 64) { if(commandByte == noteOn) pointer(3, 1, Master, ColorBasic); else if(commandByte == noteOff) blackout(3, 1); } if(noteByte == 65) { if(commandByte == noteOn) pointer(3, 2, Master, ColorBasic); else if(commandByte == noteOff) blackout(3, 2); } if(noteByte == 67) { if(commandByte == noteOn) pointer(3, 3, Master, ColorBasic); else if(commandByte == noteOff) blackout(3, 3); } if(noteByte == 69) { if(commandByte == noteOn) pointer(3, 4, Master, ColorBasic); else if(commandByte == noteOff) blackout(3, 4); } // end right_long if(noteByte == 72) { // C4, LEFT_LONG if(commandByte == noteOn) { for(byte i = 0; i < NUM_LEDS_PER_STRIP; i++) pointer(0, i, Master, ColorBasic); } else if(commandByte == noteOff) { // — for(byte i = 0; i < NUM_LEDS_PER_STRIP; i++) blackout(0, i); } } if(noteByte == 74) { // LEFT_SHORT if(commandByte == noteOn) { for(byte i = 0; i < NUM_LEDS_PER_STRIP; i++) pointer(1, i, Master, ColorBasic); } else if(commandByte == noteOff) { for(byte i = 0; i < NUM_LEDS_PER_STRIP; i++) blackout(1, i); } } if(noteByte == 76) { // RIGHT_SHORT if(commandByte == noteOn) { for(byte i = 0; i < NUM_LEDS_PER_STRIP; i++) pointer(2, i, Master, ColorBasic); } else if(commandByte == noteOff) { for(byte i = 0; i < NUM_LEDS_PER_STRIP; i++) blackout(2, i); } } if(noteByte == 77) { // RIGHT_LONG if(commandByte == noteOn) { for(byte i = 0; i < NUM_LEDS_PER_STRIP; i++) pointer(3, i, Master, ColorBasic); } else if(commandByte == noteOff) { for(byte i = 0; i < NUM_LEDS_PER_STRIP; i++) blackout(3, i); } } // , if(noteByte == 37) { for(byte x = 0; x < NUM_STRIPS; x++) { // This inner loop will go over each led in the current strip, one at a time for(byte i = 0; i < NUM_LEDS_PER_STRIP; i++) { leds[x][i] = CRGB::Black; FastLED.show(); } } } // if(noteByte == 73){ if(commandByte == noteOn) { for(byte x = 0; x < NUM_STRIPS; x++) { for(byte i = 0; i < NUM_LEDS_PER_STRIP; i++) { leds[x][i] = CHSV(ColorBasic, 255, 255); FastLED.show(); leds[x][i] = CRGB::Black; delay(faza); // Delay } } } // end Note ON else if(commandByte == noteOff) { for(byte i = 0; i < NUM_LEDS_PER_STRIP; i++) blackout(3, i); } }// end note On // end noteByte 73 // faza , i . if(noteByte == 75 && commandByte == noteOn) { faza = map(faza, 0, 200, 0, 3); for(byte i = 255; i > 0; i--) { FastLED.showColor(CHSV(ColorBasic, 255, i)); delay(faza); } } }// end if }// end do while (Serial.available() > 2);// 3 }
void Rainbow(int delay_time) { for(int hue = 0; hue < 255; hue++) { FastLED.showColor(CHSV(hue,255,255)); delay(delay_time); } }
void loop(){ // MIDI checkMIDI(); // . , . - , , . delay(50); }
Source: https://habr.com/ru/post/225653/
All Articles