Pages: [1]   Go Down
Author Topic: Having an issue with some analog inputs on MIDI Xylophone!  (Read 116 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am building a MIDI Xylophone per the instructables website...I have 12 piezos hooked up to inputs A0 through A11 of an Arduino Mega 2560. The other 4 inputs are hooked up to ground.  All piezos are connected similarly with 1 M Ohm resistors to ground.

I am using the Arduino Serial Monitor to test them. I am only getting a response from the first 7 piezos (A0-A6) and nothing from piezos hooked up to A7-A11. I have verified that the piezos are functional through troubleshooting. Is there anything about this code that is not "enabling" A7-A11 inputs?

The base code came from here:  http://www.instructables.com/id/Arduino-Xylophone/?ALLSTEPS
The only edit I made was in this line char pinAssignments[12]. Initially, it was char pinAssignments[6] but that was creating an error even before uploading. Any ideas??? - john

Here is the complete code I am using:

Code:
//Xylophone
//Adapted for an ArduinoMega
//from Jenna deBoisblanc and Spiekenzie Labs initial code

//*******************************************************************************************************************
// User settable variables
//*******************************************************************************************************************

int pinRead;
char pinAssignments[12] ={
  'A0','A1','A2','A3','A4','A5','A6','A7','A8','A9','A10','A11'};
byte PadNote[16] = {
  57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72};         // MIDI notes from 0 to 127 (Mid C = 60)
int PadCutOff[16] =
{
  400,400,200,800,400,400,400,400,400,400,400,400,400,400,400,400};           // Minimum Analog value to cause a drum hit
int MaxPlayTime[16] = {
  90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90};               // Cycles before a 2nd hit is allowed
#define  midichannel 1;                              // MIDI channel from 0 to 15 (+1 in "real world")
boolean VelocityFlag  = true;                           // Velocity ON (true) or OFF (false)

//*******************************************************************************************************************
// Internal Use Variables
//*******************************************************************************************************************
boolean activePad[16] = {
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};                   // Array of flags of pad currently playing
int PinPlayTime[16] = {
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};                     // Counter since pad started to play
byte status1;

int pin = 0;     
int hitavg = 0;
//*******************************************************************************************************************
// Setup
//*******************************************************************************************************************
void setup()
{
  Serial.begin(57600);                                  // connect to the serial port 115200

}
//*******************************************************************************************************************
// Main Program
//*******************************************************************************************************************
void loop()
{
  for(int pin=0; pin < 16; pin++)                          //
  {
    //int pin = 3;
    //   for (pinRead=0; pinRead < 16, pin++){
    hitavg = analogRead(pinAssignments[pin]); 
    //Serial.println(hitavg);   
    // read the input pin

    if((hitavg > PadCutOff[pin]))
    {
      if((activePad[pin] == false))
      {
        if(VelocityFlag == true)
        {
          //          hitavg = 127 / ((1023 - PadCutOff[pin]) / (hitavg - PadCutOff[pin]));    // With full range (Too sensitive ?)
          hitavg = (hitavg / 8) -1 ;                                                 // Upper range
        }
        else
        {
          hitavg = 127;
        }
        MIDI_TX(144,PadNote[pin],hitavg); //note on

        PinPlayTime[pin] = 0;
        activePad[pin] = true;
      }
      else
      {
        PinPlayTime[pin] = PinPlayTime[pin] + 1;
      }
    }
    else if((activePad[pin] == true))
    {
      PinPlayTime[pin] = PinPlayTime[pin] + 1;
      if(PinPlayTime[pin] > MaxPlayTime[pin])
      {
        activePad[pin] = false;
        MIDI_TX(144,PadNote[pin],0);
      }
    }
  }
}

//*******************************************************************************************************************
// Transmit MIDI Message
//*******************************************************************************************************************
void MIDI_TX(byte MESSAGE, byte PITCH, byte VELOCITY)
{
  status1 = MESSAGE + midichannel;
  Serial.write(status1);
  Serial.write(PITCH);
  Serial.write(VELOCITY);

}

Logged

Offline Offline
Full Member
***
Karma: 6
Posts: 233
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
char pinAssignments[12] ={
  'A0','A1','A2','A3','A4','A5','A6','A7','A8','A9','A10','A11'};
Why do you have single quotes around these? You don't need them.
Logged

Pages: [1]   Go Up
Jump to: