forked from mat1jaczyyy/teensy-underlights
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3f424d
commit 4a30290
Showing
5 changed files
with
28 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,68 @@ | ||
|
||
/* | ||
* USB MIDI to WS2812B by mat1jaczyyy & 4D | ||
* ---------------------------------- | ||
* --------------------------------------- | ||
*/ | ||
|
||
/* | ||
* LED Strip definition | ||
* -------------------- | ||
*/ | ||
#include "MIDIUSB.h" | ||
#include "PitchToNote.h" | ||
|
||
const byte _NLED = 60; | ||
const byte _DPIN = 2; | ||
|
||
#include <Adafruit_NeoPixel.h> | ||
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(); | ||
// } | ||
//} | ||
//} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.