From 4a3029008001dd1996fdcdd467e799f8d70e98b9 Mon Sep 17 00:00:00 2001 From: mat1jaczyyy Date: Thu, 30 Jan 2020 20:35:51 +0100 Subject: [PATCH] Reorganize --- .../WS2812B/WS2812B.ino | 53 ++++++++++--------- {LPD8806 => Teensy3/LPD8806}/LPD8806.ino | 0 {LPD8806 => Teensy3/LPD8806}/name.c | 0 {WS2812B => Teensy3/WS2812B}/WS2812B.ino | 0 {WS2812B => Teensy3/WS2812B}/name.c | 0 5 files changed, 28 insertions(+), 25 deletions(-) rename WS2812B-Leonardo => Leonardo/WS2812B/WS2812B.ino (80%) rename {LPD8806 => Teensy3/LPD8806}/LPD8806.ino (100%) rename {LPD8806 => Teensy3/LPD8806}/name.c (100%) rename {WS2812B => Teensy3/WS2812B}/WS2812B.ino (100%) rename {WS2812B => Teensy3/WS2812B}/name.c (100%) diff --git a/WS2812B-Leonardo b/Leonardo/WS2812B/WS2812B.ino similarity index 80% rename from WS2812B-Leonardo rename to Leonardo/WS2812B/WS2812B.ino index 36e9a58..61942ab 100644 --- a/WS2812B-Leonardo +++ b/Leonardo/WS2812B/WS2812B.ino @@ -1,15 +1,13 @@ /* * USB MIDI to WS2812B by mat1jaczyyy & 4D - * ---------------------------------- + * --------------------------------------- */ /* * LED Strip definition * -------------------- */ -#include "MIDIUSB.h" -#include "PitchToNote.h" const byte _NLED = 60; const byte _DPIN = 2; @@ -17,49 +15,54 @@ const byte _DPIN = 2; #include Adafruit_NeoPixel _LED = Adafruit_NeoPixel(_NLED, _DPIN, NEO_GRB + NEO_KHZ800); +/* + * Color Palette + * Generate with retinaConverter.py (Retina 2.0+ Palette) + * ------------------------------------------------------ + */ + const byte _R[128] = {0, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 36, 73, 109, 146, 182, 219, 255}; const byte _G[128] = {0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 36, 73, 109, 146, 182, 219, 255}; const byte _B[128] = {0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 36, 73, 109, 146, 182, 219, 255}; +/* + * MIDI handler + * ------------ + */ +#include "MIDIUSB.h" +#include "PitchToNote.h" const byte _PStart = 36; // First note in array bool update = false; +void note(byte pitch, byte velocity) { + _LED.setPixelColor(pitch - _PStart, _R[velocity], _G[velocity], _B[velocity]); + update = true; +} void setup() { -_LED.begin(); -_LED.show(); + _LED.begin(); + _LED.show(); } - void loop() { midiEventPacket_t rx; do { rx = MidiUSB.read(); - if(rx.header == 0x9) noteOn(rx.byte1, rx.byte2,rx.byte3); - if(rx.header == 0x8) noteOff(rx.byte1, rx.byte2,rx.byte3); -// if(rx.header == 0xB) controlChange(rx.byte2, rx.byte3); - } - while (rx.header == 0); // hold until a MIDI message is received -} - -void noteOn(byte channel, byte pitch, byte velocity) { - _LED.setPixelColor(pitch - _PStart, _R[velocity], _G[velocity], _B[velocity]); - update = true; - _LED.show(); -} + if (rx.header == 0x9) note(rx.byte2, rx.byte3); + if (rx.header == 0x8) note(rx.byte2, 0); + } while (rx.header == 0); -void noteOff(byte channel, byte pitch, byte velocity) { - _LED.setPixelColor(pitch - _PStart, 0, 0, 0); - update = true; - _LED.show(); + if (update) { + _LED.show(); + update = false; + } } -//void controlChange(byte *data, unsigned int length) { +//void sysEx(byte *data, unsigned int length) { // if (length == 6) { // _LED.setPixelColor(*(data+1) - _PStart, *(data+2), *(data+3), *(data+4)); // update = true; -// _LED.show(); // } -//} +//} \ No newline at end of file diff --git a/LPD8806/LPD8806.ino b/Teensy3/LPD8806/LPD8806.ino similarity index 100% rename from LPD8806/LPD8806.ino rename to Teensy3/LPD8806/LPD8806.ino diff --git a/LPD8806/name.c b/Teensy3/LPD8806/name.c similarity index 100% rename from LPD8806/name.c rename to Teensy3/LPD8806/name.c diff --git a/WS2812B/WS2812B.ino b/Teensy3/WS2812B/WS2812B.ino similarity index 100% rename from WS2812B/WS2812B.ino rename to Teensy3/WS2812B/WS2812B.ino diff --git a/WS2812B/name.c b/Teensy3/WS2812B/name.c similarity index 100% rename from WS2812B/name.c rename to Teensy3/WS2812B/name.c