Go Down

Topic: HELLP!!! (Read 1 time) previous topic - next topic

inhost

Hey, I would really need some help with code, I found it on the internet, and I tried it it works, but for some reason just for analog input 0 and 1, I tried to add the analog pins in the code, didn't help, please some one help. (BTW piezo drums)



unsigned char PadNote[16] = {47,18,32,38,43,13,45,17,21,36,0,44,0,19,0,21};       
unsigned char status;
int PadCutOff[16] = {100,100,100,200,100,100,100,100,100,350,100,350,100,100,100,100};   
int MaxPlayTime[16] = {25,25,25,25,25,25,25,25,25,40,25,40,25,25,25,25};       
#define  midichannel 0;                 
boolean activePad[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};     
int PinPlayTime[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};             
boolean VelocityFlag  = true;           
int analogPin[2] = {A0,A1};
int pin = 0;
int hitavg = 0;
int pad = 0;
int r0 = 0;
int r1 = 0;
int r2 = 0;
int count = 0;
int multiplex1[8];
int multiplex2[8];

//*******************************************************************************************************************
// Setup         
//*******************************************************************************************************************

void setup()
{
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  Serial.begin(115200);                                  // connect to the serial port 115200
}

//*******************************************************************************************************************
// Main Program         
//*******************************************************************************************************************

void loop(){

  readSensors(0);
  readSensors(1);
  checkSensors(0);
  checkSensors(1);
}
void readSensors (int analogPin) {
  for(count=0; count <= 7; count++)
  {
    r2 = bitRead(count,0);
    r1 = bitRead(count,1);
    r0 = bitRead(count,2);
    digitalWrite(2, r0);
    digitalWrite(3, r1);
    digitalWrite(4, r2);
    if(analogPin==0) {
    multiplex1[count] = analogRead(analogPin);
  }
  else if(analogPin==1) {
    multiplex2[count] = analogRead(analogPin);
  }
  }
}
 
void checkSensors (int analogPin) {
  for(int pin=0; pin <=7; pin++) {
    if(analogPin==0) {
    hitavg = multiplex1[pin];
    pad=pin;
    }
    else if(analogPin==1) {
    hitavg = multiplex2[pin];
    pad=pin+8;
    }
   
    if((hitavg > PadCutOff[pad])) {
      if((activePad[pad] == false)) {
        if(VelocityFlag == true) {
          hitavg = (hitavg / 8) -1;
        }
        else {
          hitavg = 127;
        }
        MIDI_TX(144,PadNote[pad],hitavg);
        PinPlayTime[pad] = 0;
        activePad[pad] = true;
      }
      else {
        PinPlayTime[pad] = PinPlayTime[pad] + 1;
      }
    }
    else if((activePad[pad] == true)) {
      PinPlayTime[pad] = PinPlayTime[pad] + 1;
      if(PinPlayTime[pad] > MaxPlayTime[pad]) {
       activePad[pad] = false;
       MIDI_TX(128,PadNote[pad],0);
      }
    }
  }
}

void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY) {
  status = MESSAGE + midichannel;
  Serial.write(status);
  Serial.write(PITCH);
  Serial.write(VELOCITY);
}
   

AWOL

Code: [Select]
if(analogPin==0) {
    multiplex1[count] = analogRead(analogPin);
  }
  else if(analogPin==1) {
    multiplex2[count] = analogRead(analogPin);
  }

Could it be some thing to do with code only being designed to use analogue pins 0 and 1?

Please always use code tags when posting code.

marco_c

This is a big clue
Code: [Select]
int analogPin[2] = {A0,A1};
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

inhost

well I copied it so there was no titels, and don't worry i'm not that dense I tried to add other pins, but they just dont respond, and also i'm not familier with midi programing, sorry and thanks.

inhost

plz some one help me with this code, I dont know hot to make to work wit 6 analoh inputs.... please

AWOL

Quote
I tried to add other pins
So, post that code, explain what it did that you didn't expect, and what it didn't do that you did expect.
That way, we can help you.

inhost

I tried to add other pins, but the problem is that the midi notes are sent just from pin A0 and A1, and I dont understand how to expand

AWOL

Please see reply #5

inhost

Unfortunetly in complete anger and desperation I didnt save it... :/

Grumpy_Mike

Unfortunetly in complete anger and desperation I didnt save it... :/
Bit convenient. But you know what you did so try it again and post the results.

marco_c

#10
Apr 27, 2016, 12:05 am Last Edit: Apr 27, 2016, 12:05 am by marco_c
I have noticed a few questions about piezo drumpads at the moment - there must be a school assignment on!
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

inhost

No not really, Im a college student, but my speciality is electrical enginering, and saldy its just for fun, I'm not even a musician, my only programming expierience is about a month, with a plc and trying to figure out a BMS, and its my final work so, if its not to hard please help me with this, its just form my own amusment, and just tu expierience the fun of drums... I know its sounds pathetic, but thats how it is :)

pjrc

How is it both "my final work" and also "just form my own amusment"?

polymorph

I would strongly suggest you choose a better subject line next time.

Homework is not a forbidden subject here. We're happy to help, but not to do it for you.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

polymorph

You should have read "How to use this forum", a sticky-topic at the top of the list on every area hear. Especially see tip number 6:

http://forum.arduino.cc/index.php/topic,148850.0.html
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

Go Up