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
71 changes: 71 additions & 0 deletions Leonardo/WS2812B/LPD8806.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Beta testing
/*
* USB MIDI to WS2812B by mat1jaczyyy & 4D
* ---------------------------------------
*/

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

const byte _NLED = 60;
const byte _DPIN = 2;

//const byte _dLED = 4; // Data pin
//const byte _cLED = 3; // Clock pin

//#include <LPD8806.h>
//LPD8806 _LED = LPD8806(_nLED, _dLED, _cLED);

/*
* 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"

const byte _PStart = 36; // First note in array
bool update = false;
//Debug serial

//void note(byte pitch, byte velocity) {
// _LED.setPixelColor(pitch - _PStart, _R[velocity], _G[velocity], _B[velocity]); // LPD8806 uses RBG format
// 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;
// }
//}
67 changes: 67 additions & 0 deletions Leonardo/WS2812B/WS2812B.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* USB MIDI to WS2812B by mat1jaczyyy & 4D
* ---------------------------------------
*/

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

const byte _NLED = 16;
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;
// }
//}
147 changes: 147 additions & 0 deletions Leonardo/WS2812B/sketch_dec07b.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* USB MIDI to WS2812B by mat1jaczyyy & 4dvn
* ---------------------------------------
*/

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

const byte _NLED = 1;
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"
#define NUM_BUTTONS 1

const uint16_t button1 = 3;

const uint16_t buttons[NUM_BUTTONS] = {button1};
const byte notePitches[NUM_BUTTONS] = {pitchC2};

uint16_t notesTime[NUM_BUTTONS];
uint16_t pressedButtons = 0x00;
uint16_t previousButtons = 0x00;
uint16_t intensity;

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

for (int i = 0; i < NUM_BUTTONS; i++)
pinMode(buttons[i], INPUT_PULLUP);
}

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

// First parameter is the event type (0x0B = control change).
// Second parameter is the event type, combined with the channel.
// Third parameter is the control number number (0-119).
// Fourth parameter is the control value (0-127).

void controlChange(byte channel, byte control, byte value) {
midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
MidiUSB.sendMIDI(event);
}

void readButtons()
{
for (int i = 0; i < NUM_BUTTONS; i++)
{
if (digitalRead(buttons[i]) == LOW)
{
bitWrite(pressedButtons, i, 1);
delay(2);
}
else
bitWrite(pressedButtons, i, 0);
}
}

void playNotes()
{
for (int i = 0; i < NUM_BUTTONS; i++)
{
if (bitRead(pressedButtons, i) != bitRead(previousButtons, i))
{
if (bitRead(pressedButtons, i))
{
bitWrite(previousButtons, i , 1);
noteOn(0, notePitches[i], 100);
MidiUSB.flush();
}
else
{
bitWrite(previousButtons, i , 0);
noteOff(0, notePitches[i], 0);
MidiUSB.flush();
}
}
}
}

// First parameter is the event type (0x09 = note on, 0x08 = note off).
// Second parameter is note-on/note-off, combined with the channel.
// Channel can be anything between 0-15. Typically reported to the user as 1-16.
// Third parameter is the note number (48 = middle C).
// Fourth parameter is the velocity (64 = normal, 127 = fastest).

void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
}

void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
}


//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.