Help with LED Lighting / Sending Midi / and Looping

Hey guys, I feel dumb not being able to figure this out but my knowledge of coding is very minimal so I'm kind of just scrapping things together.

I have an LED controller with 5 touchpad triggers. I want it to light up when I press and hold the trigger, but only send one midi note. Right now I have a loop but it makes the LED strobe and send a new midi note every time the loop refreshes. Basically I need the note to be sent once, and the LED to hold as long as my finger stays on the touch pad. Here is the code I have now. Thank youuuu


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

It sounds like you need to detect when the pad becomes touched rather than when it is touched.

Look at the StateChangeDetection example in the IDE and take note of the advice in read this before posting a programming question with regard to posting code.

The code you posted is horridly formatted, and won't even compile (where does setup() end?).

Put EVERY { on a line BY ITSELF.
Put EVERY } on a line BY ITSELF.

Use Tools + Auto Format to fix the piss-poor indenting.

I'm willing to bet that it then becomes perfectly obvious what the problem is. It's probably the left shift by a smiley face.

Post your code PROPERLY. Read the stickies (that you were supposed to read BEFORE you posted) to learn how.

Sorry I'm brand new to this clearly. Sooo, be nice?? I agree the code is shit, someone else made it and I'm just trying to get it to work. Clearly they didn't really know what they were doing either on the software side. I really don't know much about coding in general but this is close and works ok, just the two problems I mentioned up top. Any help would really be appreciated

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

Any help would really be appreciated

When you can't follow simple instructions? Forget it.

Ok how about this. Looked into a lot of this forum and changed the code a bit. I have two videos here to help show the problem too. I'm sure the code sucks, I've never coded anything in my life so doing what I can. The light works well now but I can't get the repeated notes to stop...


#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;
int m = 0;


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() 
{
    note();
    StopMidiLoop();
    light();  
}

void note() 
{

 if (int m = 0 ) 
 {  
     playMIDINote(0, 0, 0);
    }
    else if (cap.touched() & (1 << 0)) 
    {  
     playMIDINote(1, 1, 127);
      digitalWrite(n1,HIGH);
    }
     else if (cap.touched() & (1 << 2)) 
     { 
      playMIDINote(1, 2, 127);
      digitalWrite(n2,HIGH);
      }
     else if (cap.touched() & (1 << 4)) 
     { 
      playMIDINote(1, 3, 127);
      digitalWrite(n3,HIGH);
      }
      else if (cap.touched() & (1 << 6)) 
      { 
      playMIDINote(1, 4, 127);
     digitalWrite(n4,HIGH);
      }
     else if (cap.touched() & (1 << 8)) 
     { 
      playMIDINote(1, 5, 127);
     digitalWrite(n5,HIGH);
      }
  }
  
void StopMidiLoop()  
{
  if (cap.touched())  
  {
  m = 0;
  }
else if (!(cap.touched()) ) 
{
  m = 1;

}
}


void light() {

    if (cap.touched() & (1 << 0)) 
    { 
      LED() ;
      }
     else if (cap.touched() & (1 << 2)) 
     { 
        LED();
      }
     else if (cap.touched() & (1 << 4)) 
     { 
      LED();
      }
      else if (cap.touched() & (1 << 6)) 
      { 
        LED();
      }
     else if (cap.touched() & (1 << 8)) 
     { 
        LED();
      }
     else if (!(cap.touched())) 
     { 
     LEDoff();
     } 
  }
   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);

}

I'm pretty certain the your problem is here

void note()
{

 if (int m = 0 )

As far as I can see, you want m to be a global which also gets modified by StopMidiLoop().
You're declaring m as a new local variable

change that line to if (m == 0) and see what happens :wink:

darrob:
change that line to if (m == 0) and see what happens :wink:

Ohhhh I think you're on to something. Its spitting out all of the negative channel I have in there as "playMIDINote(0, 0, 0);", but its not giving me the actually midi note I want now. Think we're close

So. Are you expecting the code to play notes when you press? or when you stop touching?

StopMidiLoop() appears to say "stop playing when I touch" (ie m = 0 when touched)
whereas note() appears to say "play notes when I touch".

try changing StopMidiLoop() to reflect what you're trying to do

Well my goal was to have it play once when pressed, then turn off even time it loops until it is released. Then on release it allows one more play. Does the code not say that?

I just want to be able to hold the panel down, the light stays on but only one note plays

I'll offer a cleaned up loop() function that might come close to doing what you want and should be more manageable.

Not sure what those writes to n1-n5 are doing, only n5 ever gets written LOW, I'm assuming that is leftover code. Anyhow, follow the comments and decide if you like this better than what you have. (I"m not sure if stopping the note is necessary.)

int currentNote = (-1);
int padTouched = 0;

void loop()
{

  padTouched = cap.touched();

  // if a pad is touched and no note playing
  if ( padTouched && (currentNote < 0) )
  {

    // turn on LEDs
    LED();

    // check 5 pads
    for (int pad = 0; pad < 5; pad++)
    {
      // if this pad is touched
      if ( padTouched & (1 << (pad * 2)) )
      {
        currentNote = pad + 1; // record current note
        break;                // stop looking

      } // if
    } // for

    // play note
    playMIDINote(1, currentNote, 127);

  } else if ( !padTouched ) {

    // stop note?
    playMIDINote(1, currentNote, 0);

    // no current note
    currentNote = (-1);

    // turn LEDs off
    LEDoff();

  } // else


}

No.
Your code, as written will play nothing when touched, and play nothing when not touched.
If you have changed StopMidiLoop() as suggested, it will play one note (repeatedly) while touched (the note played appears to depend on where you touched) , and nothing while not touched.

Blue Eyes it Worked! Slight problem though my midi receiver is getting this when I'm not touching anything. Know what this is coming from?

"+409.039 - Warning: got a status byte when we were expecting 2 more data bytes, sending possibly incomplete MIDI message 0x90
+409.039 - Serial In: Ch 1: Note %2 on velocity %3"

#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;
int m = 0;
int currentNote = (-1);
int padTouched = 0;


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

{

  padTouched = cap.touched();

  // if a pad is touched and no note playing
  if ( padTouched && (currentNote < 0) )
  {

    // turn on LEDs
    LED();

    // check 5 pads
    for (int pad = 0; pad < 5; pad++)
    {
      // if this pad is touched
      if ( padTouched & (1 << (pad * 2)) )
      {
        currentNote = pad + 1; // record current note
        break;                // stop looking

      } // if
    } // for

    // play note
    playMIDINote(1, currentNote, 127);

  } else if ( !padTouched ) {

    // stop note?
    playMIDINote(1, currentNote, 0);

    // no current note
    currentNote = (-1);

    // turn LEDs off
    LEDoff();

  } // else


}

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

}

Ok fixed this but have one more question if you'd be so nice... I'm trying to fade out the lights slower, but I'm running up against two problems. I can have the lights snake out which look like silly Christmas lights. Or I can make it fade out and out but it delays the whole controller and/or makes it unplayable. Any suggestion how to get the fade out style of this code

// Pause = delay between transitions
// Steps = number of steps
// R, G, B = Full-on RGB values
void breathe(int pause, int steps, byte R, byte G, byte B) { 

  int tmpR, tmpG, tmpB;         // Temp values

  // Fade up
  for (int s=1; s<=steps; s++) {
    tmpR = (R * s) / steps;     // Multiply first to avoid truncation errors  
    tmpG = (G * s) / steps;
    tmpB = (B * s) / steps;

    for (int i=0; i<numPix; i++) {
      myNeoPixels.setPixelColor(i,tmpR,tmpG,tmpB);
    }
    myNeoPixels.show();
    delay(pause);
  }    

  // Fade down
  for (int s=steps; s>0; s--) {
    tmpR = (R * s) / steps;     // Multiply first to avoid truncation errors  
    tmpG = (G * s) / steps;
    tmpB = (B * s) / steps;

    for (int i=0; i<numPix; i++) {
      myNeoPixels.setPixelColor(i,tmpR,tmpG,tmpB);
    }
    myNeoPixels.show();
    delay(pause);
  }    

  delay(pause * 30);
}

Into my current code??

#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;
int m = 0;
int currentNote = (-1);
int padTouched = 0;


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

{

  padTouched = cap.touched();

  // if a pad is touched and no note playing
  if ( padTouched && (currentNote < 0) )
  {

    // turn on LEDs
    LED();

    // check 5 pads
    for (int pad = 0; pad < 5; pad++)
    {
      // if this pad is touched
      if ( padTouched & (1 << (pad * 2)) )
      {
        currentNote = pad + 1; // record current note
        break;                // stop looking

      } // if
    } // for

    // play note
    playMIDINote(1, (currentNote+44), 127);

  } else if ( !padTouched ) {

    // stop note?
    playMIDINote(1, (currentNote+44), 0);

    // no current note
    currentNote = (-1);

    // turn LEDs off
    LEDoff();

  } // else


}

 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(255,255,255)); // 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);

}