Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leonardo support #1

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
68 changes: 68 additions & 0 deletions Leonardo/WS2812B/WS2812B.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

/*
* USB MIDI to WS2812B by mat1jaczyyy & 4D
* ---------------------------------------
*/

/*
* LED Strip definition
* --------------------
*/

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();
}

void loop() {
midiEventPacket_t rx;
do {
rx = MidiUSB.read();
if (rx.header == 0x9) note(rx.byte2, rx.byte3);
if (rx.header == 0x8) note(rx.byte2, 0);
} while (rx.header == 0);

if (update) {
_LED.show();
update = false;
}
}

//void sysEx(byte *data, unsigned int length) {
// if (length == 6) {
// _LED.setPixelColor(*(data+1) - _PStart, *(data+2), *(data+3), *(data+4));
// update = true;
// }
//}
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# LED Strip MIDI for Teensy - controlling LED strips via MIDI
# LED Strip MIDI for Teensy, Atmega32u4 - controlling LED strips via MIDI

This Arduino project allows for controlling a LED strip from a DAW program (via MIDI) over a Teensy microcontroller.

Expand All @@ -7,11 +7,12 @@ This Arduino project allows for controlling a LED strip from a DAW program (via
* LED Strip
* The **LPD8806** and **WS2812B** strips are implemented in separate Arduino projects.
* USB Development Board
* A **32-bit PJRC Teensy** is highly recommended. A [Teensy-LC](https://www.pjrc.com/store/teensylc.html) was used while developing this project and is officially supported alongside other Teensy 3 models.
* Teensy 2 (8-bit) and certain Arduino boards might work, but have not been tested and are not officially supported.
* A **32-bit PJRC Teensy** is highly recommended. A [Teensy-LC](https://www.pjrc.com/store/teensylc.html) was used while developing this project and is officially supported alongside other Teensy 3 models.\
* Most Arduino atmega32u4 boards should work (such as the [Arduino Leonardo](https://store.arduino.cc/arduino-leonardo-with-headers), these have been tested and are unofficially supported (thanks [4dvn](https://github.com/4dvn)!).
* Teensy 2 (8-bit) boards might work with modifications, but are not supported.
* [Arduino Software](https://www.arduino.cc/en/Main/Software)
* Developed with **version 1.8.5**, but older versions will likely work.
* Also requires [Teensyduino](https://www.pjrc.com/teensy/teensyduino.html), and the [LPD8806 Arduino library](https://github.com/adafruit/LPD8806) if you're using the LPD8806.
* Additionally requires [Teensyduino](https://www.pjrc.com/teensy/teensyduino.html) if you're using a Teensy 3 board, and the [LPD8806 Arduino library](https://github.com/adafruit/LPD8806) if you're using the LPD8806.
* OS
* **Windows, Linux and macOS** are officially supported.
* DAW Software
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.