Hey guys really need some help here. Not a great coder and been picking away at this. I have a simple midi controller, 5 panels that send one midi note to Ableton, and every time any of the panels are touched an LED goes on. Right now how I have it it works, but if I hold my finger on the panel it triggers a new note on repeat and the light strobes. Clearly the program is looping. What I need is for the program to trigger one note and the light stays on till I release my finger. Any suggestions?? Thanks
#include <Adafruit_NeoPixel.h>
#ifdef AVR
#include <avr/power.h>
#endif#include <Wire.h>
#include "Adafruit_MPR121.h"
Adafruit_MPR121 cap = Adafruit_MPR121();
uint16_t lasttouched = 0;
uint16_t currtouched = 0;
#define PIN 6
#define NUMPIXELS 77
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#include <MIDI.h>int n1 = 2;
int n2 = 3;
int n3 = 4;
int n4 = 5;
int n5 = 7;void setup() {
pixels.begin(); // This initializes the NeoPixel library.Serial.begin(115200);
pinMode(n1,OUTPUT);
pinMode(n2,OUTPUT);
pinMode(n3,OUTPUT);
pinMode(n4,OUTPUT);
pinMode(n5,OUTPUT);if (!cap.begin(0x5A)) {
Serial.println("MPR121 not found, check wiring?");
while (1);
}
for(uint8_t j=0;j<77;j++){
pixels.setPixelColor(j, pixels.Color(0,150,120)); // Moderately bright green color.
}
pixels.show(); // This sends the updated pixel color to the hardware.
delay(127);
for(uint8_t j=0;j<77;j++){
pixels.setPixelColor(j, pixels.Color(0,0,0)); // Moderately bright green color.
}
pixels.show(); // This sends the updated pixel color to the hardware.
delay(127);for(uint8_t j=0;j<77;j++){
pixels.setPixelColor(j, pixels.Color(0,150,120)); // Moderately bright green color.
}
pixels.show(); // This sends the updated pixel color to the hardware.
delay(127);for(uint8_t j=0;j<77;j++){
pixels.setPixelColor(j, pixels.Color(0,0,0)); // Moderately bright green color.
}
pixels.show(); // This sends the updated pixel color to the hardware.
cap.begin();
}void loop() {
cap.touched();
for (uint16_t i=0; i<12; i++) {if (cap.touched() & (1 << 0)) {
LED() ;
playMIDINote(1, 1, 127);
digitalWrite(n1,HIGH);}
else if (cap.touched() & (1 << 2)) {
LED();
playMIDINote(1, 2, 127);
digitalWrite(n2,HIGH);}
else if (cap.touched() & (1 << 4)) {
LED();
playMIDINote(1, 3, 127);
digitalWrite(n3,HIGH);}
else if (cap.touched() & (1 << 6)) {
LED();
playMIDINote(1, 4, 127);
digitalWrite(n4,HIGH);}
else if (cap.touched() & (1 << 8)) {
LED();
playMIDINote(1, 5, 127);
digitalWrite(n5,HIGH);}
else
digitalWrite(n5,LOW);
LEDoff();
break;
}
// reset our state
}void LED() {
for(int i=0;i<NUMPIXELS;i++){// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(100,150,120)); // Moderately bright green color.
}
//}
pixels.show(); // This sends the updated pixel color to the hardware.}
void LEDoff() {
for(int i=NUMPIXELS;i>0;i--){pixels.setPixelColor(i, pixels.Color(0,0,0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
}
delay(1);
}void playMIDINote(byte channel, byte note, byte velocity)
{
//MIDI channels 1-16 are really 0-15
byte noteOnStatus=0x90 + (channel-1);//Send notes to MIDI output:
Serial.write(noteOnStatus);
Serial.write(note);
Serial.write(velocity);
}