Analogue pins not working
hi all,
i complete newbie @ arduino programming, have urgent issue. have built electronic xylophone uses piezo sensors , adrunio mega 2560 detect when note struck , generate midi output. analogue pins a0-a7 seem work, pins a8-a15 not. sensors work when plugged a0-a7. i'm using hairless serial bridge transform serial out midi output. hairless recognises input a0-a7, not a8-a15. code below. appreciated.
int pinread;
char pinassignments[16] ={
'a0','a1','a2','a3','a4','a5','a6','a7','a8','a9','a10','a11','a12','a13','a14','a15'};
byte padnote[16] = {
57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72}; // midi notes 0 127 (mid c = 60)
int padcutoff[16] =
{
100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}; // minimum analog value cause drum hit
int maxplaytime[16] = {
90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90}; // cycles before 2nd hit allowed
#define midichannel 1; // midi channel 0 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 playing
int pinplaytime[16] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // counter since pad started play
byte status1;
int pin = 0;
int hitavg = 0;
//*******************************************************************************************************************
// setup
//*******************************************************************************************************************
void setup()
{
serial.begin(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 input pin
if((hitavg > padcutoff[pin]))
{
if((activepad[pin] == false))
{
if(velocityflag == true)
{
// hitavg = 127 / ((1023 - padcutoff[pin]) / (hitavg - padcutoff[pin])); // full range (too sensitive ?)
hitavg = (hitavg /
-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);
}
i complete newbie @ arduino programming, have urgent issue. have built electronic xylophone uses piezo sensors , adrunio mega 2560 detect when note struck , generate midi output. analogue pins a0-a7 seem work, pins a8-a15 not. sensors work when plugged a0-a7. i'm using hairless serial bridge transform serial out midi output. hairless recognises input a0-a7, not a8-a15. code below. appreciated.
int pinread;
char pinassignments[16] ={
'a0','a1','a2','a3','a4','a5','a6','a7','a8','a9','a10','a11','a12','a13','a14','a15'};
byte padnote[16] = {
57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72}; // midi notes 0 127 (mid c = 60)
int padcutoff[16] =
{
100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}; // minimum analog value cause drum hit
int maxplaytime[16] = {
90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90}; // cycles before 2nd hit allowed
#define midichannel 1; // midi channel 0 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 playing
int pinplaytime[16] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // counter since pad started play
byte status1;
int pin = 0;
int hitavg = 0;
//*******************************************************************************************************************
// setup
//*******************************************************************************************************************
void setup()
{
serial.begin(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 input pin
if((hitavg > padcutoff[pin]))
{
if((activepad[pin] == false))
{
if(velocityflag == true)
{
// hitavg = 127 / ((1023 - padcutoff[pin]) / (hitavg - padcutoff[pin])); // full range (too sensitive ?)
hitavg = (hitavg /
![cool 8)](https://forum.arduino.cc/smileys/arduino/cool.gif)
}
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);
}
please modify post, select code part , press # button above smileys. becomes more readable way.
can tell more sensors? - datasheet link?
what voltage generate?
can tell how did connect sensors? need pull up/down resistor?
can tell more sensors? - datasheet link?
what voltage generate?
can tell how did connect sensors? need pull up/down resistor?
Arduino Forum > Using Arduino > Sensors > Analogue pins not working
arduino
Comments
Post a Comment