Hallo,
ich würde gerne einer Funktion die Dimension für ein static Array übergeben. Leider bekomme ich die Fehlermeldung:
Arduino: 1.6.4 (Linux), Platine: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
/opt/arduino-1.6.4/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -Wextra -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10604 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -I/opt/arduino-1.6.4/hardware/arduino/avr/cores/arduino -I/opt/arduino-1.6.4/hardware/arduino/avr/variants/mega /tmp/build3892027074857907477.tmp/_150614_PV_Sensor_V001.cpp -o /tmp/build3892027074857907477.tmp/_150614_PV_Sensor_V001.cpp.o
_150614_PV_Sensor_V001.ino: In function 'int analogReadSmooth(int, byte, byte, byte)':
_150614_PV_Sensor_V001.ino:136:30: error: variable-sized object 'adcRaw' may not be initialized
_150614_PV_Sensor_V001.ino:136:30: error: storage size of 'adcRaw' isn't constant
variable-sized object 'adcRaw' may not be initialized
Meine Funktion:
int analogReadSmooth(int pin, byte cnt, byte bits, const byte smooth){
static const byte a = smooth;
//const byte a = 10; // so ginge es
static int adcRaw[a] = { 0 }; // Array init.
static byte index = 0;
static unsigned long total = 0;
// subtract the last reading:
total = total - adcRaw[index];
// read from the sensor:
adcRaw[index] = analogReadBit(pin, cnt, bits); // ADC-Pin, Samples(1-255), 'Resolution'-Bit (10-12)
// add the reading to the total:
total = total + adcRaw[index];
// advance to the next position in the array:
index = index + 1;
// if we're at the end of the array...
if (index >= smooth)
// ...wrap around to the beginning:
index = 0;
// calculate the average:
return (total / smooth);
}
Geht das überhapt? Vielen Dank! ![]()