// LED
#include "Adafruit_TLC5947.h"
#define NUM_TLC5974 1
#define data 11
#define clock 13
#define latch 10
#define oe -1 // set to -1 to not use the enable pin (its optional)
Adafruit_TLC5947 tlc = Adafruit_TLC5947(NUM_TLC5974, clock, data, latch);
// END LED
int noteIsOn0;
int noteIsOn1;
int noteIsOn2;
int noteIsOn3;
int noteIsOn4;
int noteIsOn5;
int noteIsOn6;
int noteIsOn7;
int thresh;
void setup() {
// LED Setup
Serial.begin(9600);
Serial.println("TLC5974 test");
tlc.begin();
if (oe >= 0) {
pinMode(oe, OUTPUT);
digitalWrite(oe, LOW);
}
// END LED
// Harp Setup
thresh = 480;
// End Harp
usbMIDI.setHandleControlChange(onControlChange);
}
void onControlChange(uint8_t channel, uint8_t control, uint8_t value){
if(control == 40){
if(value == 127){
tlc.setLED(0, 0, 0, 0);
delay (500);
tlc.setLED(1, 0, 0, 0);
delay (500);
tlc.setLED(2, 0, 0, 0);
delay (500);
tlc.setLED(3, 0, 0, 0);
delay (500);
tlc.setLED(4, 0, 0, 0);
delay (500);
tlc.setLED(5, 0, 0, 0);
delay (500);
tlc.setLED(6, 0, 0, 0);
delay (500);
tlc.setLED(7, 0, 0, 0);
delay (500);
}
}
if(control == 41){
if(value == 127){
tlc.setLED (0, 4095, 4095, 1);
delay (500);
tlc.setLED (1, 4095, 4095, 1);
delay (500);
tlc.setLED (2, 4095, 4095, 1);
delay (500);
tlc.setLED (3, 4095, 4095, 1);
delay (500);
tlc.setLED (4, 4095, 4095, 1);
delay (500);
tlc.setLED (5, 4095, 4095, 1);
delay (500);
tlc.setLED (6, 4095, 4095, 1);
delay (500);
tlc.setLED (7, 4095, 4095, 1);
delay (500);
}
}
}
void loop() {
// Sensor Start 0
if (noteIsOn0 == false) {
if (analogRead(0) > (thresh)) {
usbMIDI.sendNoteOn(60, (random(115,127)), 1);
tlc.setLED(0, 0, 4095, 0);
noteIsOn0 = true;
}
} else {
if (analogRead(0) < thresh) {
usbMIDI.sendNoteOff (60, 0, 1);
noteIsOn0 = false;
tlc.setLED (0, 4095, 4095, 1);
}
}
// Sensor Start 1
if (noteIsOn1 == false) {
if (analogRead(1) > thresh+30) {
usbMIDI.sendNoteOn(62, (random(115,127)), 1);
tlc.setLED(1, 0, 4095, 0);
noteIsOn1 = true;
}
} else {
if (analogRead(1) < thresh) {
usbMIDI.sendNoteOff (62, 0, 1);
noteIsOn1 = false;
tlc.setLED (1, 4095, 4095, 1);
}
}
// Sensor Start 2
if (noteIsOn2 == false) {
if (analogRead(2) > thresh) {
usbMIDI.sendNoteOn(64, (random(115,127)), 1);
tlc.setLED(2, 0, 4095, 0);
noteIsOn2 = true;
}
} else {
if (analogRead(2) < thresh) {
usbMIDI.sendNoteOff (64, 0, 1);
noteIsOn2 = false;
tlc.setLED (2, 4095, 4095, 1);
}
}
// Sensor Start 3
if (noteIsOn3 == false) {
if (analogRead(3) > thresh) {
usbMIDI.sendNoteOn(65, (random(115,127)), 1);
tlc.setLED(3, 0, 4095, 0);
noteIsOn3 = true;
}
} else {
if (analogRead(3) < thresh) {
usbMIDI.sendNoteOff (65, 0, 1);
noteIsOn3 = false;
tlc.setLED (3, 4095, 4095, 1);
}
}
// Sensor Start 4
if (noteIsOn4 == false) {
if (analogRead(4) > thresh + 25) {
usbMIDI.sendNoteOn(67, (random(115,127)), 1);
tlc.setLED(4, 0, 4095, 0);
noteIsOn4 = true;
}
} else {
if (analogRead(4) < thresh) {
usbMIDI.sendNoteOff (67, 0, 1);
noteIsOn4 = false;
tlc.setLED (4, 4095, 4095, 1);
}
}
// Sensor Start 5
if (noteIsOn5 == false) {
if (analogRead(5) > thresh) {
usbMIDI.sendNoteOn(69, (random(115,127)), 1);
tlc.setLED(5, 0, 4095, 0);
noteIsOn5 = true;
}
} else {
if (analogRead(5) < thresh) {
usbMIDI.sendNoteOff (69, 0, 1);
noteIsOn5 = false;
tlc.setLED (5, 4095, 4095, 1);
}
}
// Sensor Start 6
if (noteIsOn6 == false) {
if (analogRead(6) > thresh) {
usbMIDI.sendNoteOn(71, (random(115,127)), 1);
tlc.setLED(6, 0, 4095, 0);
noteIsOn6 = true;
}
} else {
if (analogRead(6) < thresh) {
usbMIDI.sendNoteOff (71, 0, 1);
noteIsOn6 = false;
tlc.setLED (6, 4095, 4095, 1);
}
}
// Sensor Start 7
if (noteIsOn7 == false) {
if (analogRead(7) > thresh) {
usbMIDI.sendNoteOn(72, (random(115,127)), 1);
tlc.setLED(7, 0, 4095, 0);
noteIsOn7 = true;
}
} else {
if (analogRead(7) < thresh) {
usbMIDI.sendNoteOff (72, 0, 1);
noteIsOn7 = false;
tlc.setLED (7, 4095, 4095, 1);
}
}
// END Sensors
while (usbMIDI.read()) {}
tlc.write();
delay(5);
}