with "average lib" and on "interrupt" I receive this message :
"call of overloaded 'mean (volatile int&, int)' is ambiguous"
BeatMyLife_04.cpp: In function 'void __vector_7()':
Interrupt:87: error: call of overloaded 'mean(volatile int [20], int)' is ambiguous
/Users/florent/Documents/Arduino/libraries/Average/Average.h:39: note: candidates are: int mean(int*, int)
/Users/florent/Documents/Arduino/libraries/Average/Average.h:40: note: unsigned int mean(unsigned int*, int)
sample of my code is :
volatile int amp = 300;
volatile int strList[20]; // make list of 20 elements
volatile int AvAmp; // average result
for(int AverageAmp = 0; AverageAmp < 20; AverageAmp++)
{
strList[AverageAmp] = amp;
AvAmp = mean (strList, 20);
}
if anyone can help me about what the wrong message says ? and how correct it ?
Interrupt:87: error: call of overloaded 'mean(volatile int [20], int)' is ambiguous
/Users/florent/Documents/Arduino/libraries/Average/Average.h:39: note: candidates are: int mean(int*, int)
/Users/florent/Documents/Arduino/libraries/Average/Average.h:40: note: unsigned int mean(unsigned int*, int)
Looks like you are trying to pass an array to the function. Don't put the array subscript in the mean function call ("'mean(volatile int [20], int)'"). The name of the array is all you need as that is a pointer to the data. I am guessing the second parameter is the size of the array, and that is an integer.
Why is the variable defined as volatile? Only global variables, accessed by the ISR and the rest of the code need to be volatile. If the array of values is only used to find a mean, then the array should not be volatile, since it is not used outside the ISR (or functions called only from the ISR).
yes, if I don't use "volatile" and just "int" I haven't wrong message but "interrupt" and card stop !
I used an diecimilla
also the "amp" value whose on the first code is a "volatile" function whose on interrupt code.
here the root of interrupt code ;
void interruptSetup(){
// Initializes Timer2 to throw an interrupt every 2mS.
TCCR2A = 0x02; // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE
TCCR2B = 0x06; // DON'T FORCE COMPARE, 256 PRESCALER
OCR2A = 0X7C; // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE
TIMSK2 = 0x02; // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND OCR2A
sei(); // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED
}
ISR(TIMER2_COMPA_vect)
{ // triggered when Timer2 counts to 124
cli(); // disable interrupts while we do this
Signal = analogRead(pulsePin); // read the Pulse Sensor
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// do average value...
for(int AverageAmp = 0; AverageAmp < 100; AverageAmp++)
{
strList[AverageAmp] = amp;
AvAmp = mean (strList, 100);
}
// ---- Finger in contact / hold new beat / --------------------- //
if ( AvAmp < 150 && BPM < 250 && N < 500 )
{
Push = 1 ;
PulseTime = runningTotal*2 ;
}
else Push = 0;
}
}
~~~~~~~~~~~~~~~
amp = P - T; // get amplitude of the pulse wave
}
sei(); // enable interrupts when youre done!
}
I thinks I search an other way than used average...