From 61401419c709e1d8622dba385dbb2f6651087f92 Mon Sep 17 00:00:00 2001 From: 4dvn Date: Sat, 25 Jan 2020 00:04:54 +0700 Subject: [PATCH 01/17] Create WS2812B-Leonardo Underlights support atmega32u4 boards --- WS2812B-Leonardo | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 WS2812B-Leonardo diff --git a/WS2812B-Leonardo b/WS2812B-Leonardo new file mode 100644 index 0000000..66779d8 --- /dev/null +++ b/WS2812B-Leonardo @@ -0,0 +1,55 @@ +#include "MIDIUSB.h" +#include "PitchToNote.h" + +const byte _NLED = 64; +const byte _DPIN = 2; + +#include +Adafruit_NeoPixel _LED = Adafruit_NeoPixel(_NLED, _DPIN, NEO_GRB + NEO_KHZ800); + +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}; + + + +const byte _PStart = 36; // First note in array +bool update = false; + + +void setup() { +_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(); +} + +void noteOff(byte channel, byte pitch, byte velocity) { + _LED.setPixelColor(pitch - _PStart, 0, 0, 0); + update = true; + _LED.show(); +} + +//void controlChange(byte *data, unsigned int length) { +// if (length == 6) { +// _LED.setPixelColor(*(data+1) - _PStart, *(data+2), *(data+3), *(data+4)); +// update = true; +// _LED.show(); +// } +//} From fa3edcf1300459fe463420f25793ede31d3aab0b Mon Sep 17 00:00:00 2001 From: 4dvn Date: Sat, 25 Jan 2020 00:06:26 +0700 Subject: [PATCH 02/17] Update README.md Adding ws2812b-leonardo code --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 235703c..85d13f4 100644 --- a/README.md +++ b/README.md @@ -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. @@ -8,7 +8,7 @@ This Arduino project allows for controlling a LED strip from a DAW program (via * 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. + * Teensy 2 (8-bit) and certain Arduino boards might work, tested and 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. From 4a5f5f61c33baacf28609d6a20b7a925f1af4f7e Mon Sep 17 00:00:00 2001 From: 4dvn Date: Sat, 25 Jan 2020 01:25:54 +0700 Subject: [PATCH 03/17] Update WS2812B-Leonardo --- WS2812B-Leonardo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WS2812B-Leonardo b/WS2812B-Leonardo index 66779d8..411f713 100644 --- a/WS2812B-Leonardo +++ b/WS2812B-Leonardo @@ -1,7 +1,7 @@ #include "MIDIUSB.h" #include "PitchToNote.h" -const byte _NLED = 64; +const byte _NLED = 60; const byte _DPIN = 2; #include From 8ee14a6846b49c42d03d03c75afd51d292b977e6 Mon Sep 17 00:00:00 2001 From: 4dvn Date: Sat, 25 Jan 2020 01:27:13 +0700 Subject: [PATCH 04/17] Update WS2812B-Leonardo Adding contribute --- WS2812B-Leonardo | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/WS2812B-Leonardo b/WS2812B-Leonardo index 411f713..36e9a58 100644 --- a/WS2812B-Leonardo +++ b/WS2812B-Leonardo @@ -1,3 +1,13 @@ + +/* + * USB MIDI to WS2812B by mat1jaczyyy & 4D + * ---------------------------------- + */ + +/* + * LED Strip definition + * -------------------- + */ #include "MIDIUSB.h" #include "PitchToNote.h" From ea016474a0f9af388e8fd4512ed3d6552e896939 Mon Sep 17 00:00:00 2001 From: 4dvn Date: Sat, 25 Jan 2020 01:44:47 +0700 Subject: [PATCH 05/17] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 85d13f4..6fe5695 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This Arduino project allows for controlling a LED strip from a DAW program (via * 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, tested and supported. + * Teensy 2 (8-bit) not work and certain Arduino atmega32u4 boards might work, tested and 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. From a3f424d8256aadc0a4f014609c452e61e1231ab1 Mon Sep 17 00:00:00 2001 From: mat1jaczyyy Date: Thu, 30 Jan 2020 21:28:55 +0100 Subject: [PATCH 06/17] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6fe5695..1f5939d 100644 --- a/README.md +++ b/README.md @@ -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) not work and certain Arduino atmega32u4 boards might work, tested and 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 From 4a3029008001dd1996fdcdd467e799f8d70e98b9 Mon Sep 17 00:00:00 2001 From: mat1jaczyyy Date: Thu, 30 Jan 2020 20:35:51 +0100 Subject: [PATCH 07/17] 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 From 1ee9f8b02e94ba4ae4f99550e6e8ffd76aa4c0da Mon Sep 17 00:00:00 2001 From: 4dvn Date: Sat, 1 Feb 2020 15:20:08 +0700 Subject: [PATCH 08/17] Update WS2812B.ino --- Leonardo/WS2812B/WS2812B.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Leonardo/WS2812B/WS2812B.ino b/Leonardo/WS2812B/WS2812B.ino index 61942ab..14005fb 100644 --- a/Leonardo/WS2812B/WS2812B.ino +++ b/Leonardo/WS2812B/WS2812B.ino @@ -31,7 +31,7 @@ const byte _B[128] = {0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0 */ #include "MIDIUSB.h" -#include "PitchToNote.h" +//#include "PitchToNote.h" const byte _PStart = 36; // First note in array bool update = false; @@ -65,4 +65,4 @@ void loop() { // _LED.setPixelColor(*(data+1) - _PStart, *(data+2), *(data+3), *(data+4)); // update = true; // } -//} \ No newline at end of file +//} From f2ab6852bdb77183c25753fac21dee4d08cad28d Mon Sep 17 00:00:00 2001 From: 4dvn Date: Wed, 5 Feb 2020 17:11:09 +0700 Subject: [PATCH 09/17] Create LPD8806.ino --- Leonardo/WS2812B/LPD8806.ino | 1 + 1 file changed, 1 insertion(+) create mode 100644 Leonardo/WS2812B/LPD8806.ino diff --git a/Leonardo/WS2812B/LPD8806.ino b/Leonardo/WS2812B/LPD8806.ino new file mode 100644 index 0000000..bb68018 --- /dev/null +++ b/Leonardo/WS2812B/LPD8806.ino @@ -0,0 +1 @@ +// Beta testing From f23a20f3db5c5d2d78e8c2ef28f8541147982ff2 Mon Sep 17 00:00:00 2001 From: 4dvn Date: Wed, 5 Feb 2020 17:11:49 +0700 Subject: [PATCH 10/17] Update WS2812B.ino --- Leonardo/WS2812B/WS2812B.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/Leonardo/WS2812B/WS2812B.ino b/Leonardo/WS2812B/WS2812B.ino index 14005fb..e8a30e0 100644 --- a/Leonardo/WS2812B/WS2812B.ino +++ b/Leonardo/WS2812B/WS2812B.ino @@ -1,4 +1,3 @@ - /* * USB MIDI to WS2812B by mat1jaczyyy & 4D * --------------------------------------- From 868a0308526fabcec1822aa7166279e1a9add892 Mon Sep 17 00:00:00 2001 From: 4dvn Date: Wed, 5 Feb 2020 17:12:11 +0700 Subject: [PATCH 11/17] Update LPD8806.ino --- Leonardo/WS2812B/LPD8806.ino | 67 ++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/Leonardo/WS2812B/LPD8806.ino b/Leonardo/WS2812B/LPD8806.ino index bb68018..1bc021a 100644 --- a/Leonardo/WS2812B/LPD8806.ino +++ b/Leonardo/WS2812B/LPD8806.ino @@ -1 +1,68 @@ // Beta testing +/* + * USB MIDI to WS2812B by mat1jaczyyy & 4D + * --------------------------------------- + */ + +/* + * LED Strip definition + * -------------------- + */ + +const byte _NLED = 60; +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(); +} + +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; +// } +//} From 5ab12dd7c903eacfdb70f5709766a43f1e3d7b00 Mon Sep 17 00:00:00 2001 From: 4dvn Date: Wed, 5 Feb 2020 17:18:05 +0700 Subject: [PATCH 12/17] Update LPD8806.ino --- Leonardo/WS2812B/LPD8806.ino | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Leonardo/WS2812B/LPD8806.ino b/Leonardo/WS2812B/LPD8806.ino index 1bc021a..e916a89 100644 --- a/Leonardo/WS2812B/LPD8806.ino +++ b/Leonardo/WS2812B/LPD8806.ino @@ -12,8 +12,11 @@ const byte _NLED = 60; const byte _DPIN = 2; -#include -Adafruit_NeoPixel _LED = Adafruit_NeoPixel(_NLED, _DPIN, NEO_GRB + NEO_KHZ800); +//const byte _dLED = 4; // Data pin +//const byte _cLED = 3; // Clock pin + +//#include +//LPD8806 _LED = LPD8806(_nLED, _dLED, _cLED); /* * Color Palette @@ -37,7 +40,7 @@ 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]); + _LED.setPixelColor(pitch - _PStart, _R[velocity], _G[velocity], _B[velocity]); // LPD8806 uses RBG format update = true; } From 91346052c912c1540d43dd7ac1fb176053a83842 Mon Sep 17 00:00:00 2001 From: 4dvn Date: Wed, 5 Feb 2020 17:19:32 +0700 Subject: [PATCH 13/17] Update LPD8806.ino --- Leonardo/WS2812B/LPD8806.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Leonardo/WS2812B/LPD8806.ino b/Leonardo/WS2812B/LPD8806.ino index e916a89..40b19bf 100644 --- a/Leonardo/WS2812B/LPD8806.ino +++ b/Leonardo/WS2812B/LPD8806.ino @@ -38,12 +38,13 @@ const byte _B[128] = {0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0 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(); From 6fea9545601cefe007ed8edb0ce3ec35c06f518d Mon Sep 17 00:00:00 2001 From: 4dvn Date: Wed, 5 Feb 2020 17:20:46 +0700 Subject: [PATCH 14/17] Update LPD8806.ino --- Leonardo/WS2812B/LPD8806.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Leonardo/WS2812B/LPD8806.ino b/Leonardo/WS2812B/LPD8806.ino index 40b19bf..0df8b87 100644 --- a/Leonardo/WS2812B/LPD8806.ino +++ b/Leonardo/WS2812B/LPD8806.ino @@ -39,12 +39,12 @@ const byte _B[128] = {0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0 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 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(); From ca260629373e345d341e93f216c5ac5de951af41 Mon Sep 17 00:00:00 2001 From: 4dvn Date: Tue, 18 Feb 2020 21:13:54 +0700 Subject: [PATCH 15/17] Update LPD8806.ino --- Leonardo/WS2812B/LPD8806.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/Leonardo/WS2812B/LPD8806.ino b/Leonardo/WS2812B/LPD8806.ino index 0df8b87..0894ce7 100644 --- a/Leonardo/WS2812B/LPD8806.ino +++ b/Leonardo/WS2812B/LPD8806.ino @@ -34,7 +34,6 @@ const byte _B[128] = {0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0 */ #include "MIDIUSB.h" -//#include "PitchToNote.h" const byte _PStart = 36; // First note in array bool update = false; From 732c4961141e8591690786ea67b559c54def1ba2 Mon Sep 17 00:00:00 2001 From: 4dvn Date: Sun, 6 Dec 2020 19:54:34 +0700 Subject: [PATCH 16/17] Update WS2812B.ino --- Leonardo/WS2812B/WS2812B.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Leonardo/WS2812B/WS2812B.ino b/Leonardo/WS2812B/WS2812B.ino index e8a30e0..d8e7756 100644 --- a/Leonardo/WS2812B/WS2812B.ino +++ b/Leonardo/WS2812B/WS2812B.ino @@ -8,7 +8,7 @@ * -------------------- */ -const byte _NLED = 60; +const byte _NLED = 16; const byte _DPIN = 2; #include From 31f35acfbf68c4782250709f32ec1286277c3ce0 Mon Sep 17 00:00:00 2001 From: 4dvn Date: Mon, 7 Dec 2020 11:26:41 +0700 Subject: [PATCH 17/17] Add files via upload --- Leonardo/WS2812B/sketch_dec07b.ino | 147 +++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 Leonardo/WS2812B/sketch_dec07b.ino diff --git a/Leonardo/WS2812B/sketch_dec07b.ino b/Leonardo/WS2812B/sketch_dec07b.ino new file mode 100644 index 0000000..6b4e8ee --- /dev/null +++ b/Leonardo/WS2812B/sketch_dec07b.ino @@ -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 _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; +// } +//}