Pages: [1]   Go Down
Author Topic: drum kit arduino mega 2560  (Read 131 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, my name is Sylvain, I am in the objective to create an drum kit midi wicht arduino mega 2560.
I need you, because I try to use my pedal of sustain, to close my hi-hat. I have to find on your forum a code, but I try to add it the swicht.
Could you help me?
Exemple: (A0, is my hi-hat...)

Thank you!


Quote
#define  MAX_PIEZO  9

uint8_t piezo[MAX_PIEZO] = { A0, A1, A2, A3, A4, A5, A6, A7, A8 };
uint8_t drumType[MAX_PIEZO] = { 9, 8, 7, 6, 5, 4, 3, 2, 1 };

const int threshold = 500; 

void setup()
{
  for (uint8_t i=0; i<MAX_PIEZO; i++)
    pinMode(piezo, INPUT);

  Serial.begin(57600);     
}

void MidiTX(unsigned char StatusByte, unsigned char Note, unsigned char Val)
{
  Serial.write(StatusByte);
  Serial.write(Note);
  Serial.write(Val);
}

void ProcessPiezo(uint8_t p)
{
  uint16_t sensorReading = analogRead(piezo[p]);
  uint16_t  val;

  if (sensorReading > threshold)
  {
    uint32_t oldcas = millis() + 5;
   
    // this part of the code looks complex
    // explain what you are trying to do?
    while (analogRead(piezo[p]) > threshold)
    {
      if (millis() >= oldcas)
      {
        val = analogRead(piezo[p]) / 9;
      }
    }
   
    MidiTX(144, drumType[p], val);
    MidiTX(128, drumType[p], val);
  }
}

void loop()
{
  for (uint8_t i=0; i<MAX_PIEZO; i++)
    ProcessPiezo(i);
}
Logged

Pages: [1]   Go Up
Jump to: