Hello,
I am trying to write a program where one aspect of it is writing a running average for loop. An error that keeps coming up is: invalid types 'int[int]' for array subscripts. The error appears on the line: sum = sum + value ;
Does anyone know how to fix this error? Or is there an alternate way to calculate a running average?
Thanks in advance.
/* Use a photoresistor (or photocell) to turn on an LED in the dark
- More info and circuit schematic: How to use photocell with Arduino - Ardumotive Arduino Greek Playground*
_ Dev: Michalis Vasilakis // Date: 8/6/2015 // www.ardumotive.com */_
#include <BlynkSimpleRedBear_Duo.h>
SYSTEM_MODE(MANUAL);
//Variables
void setup(){ - //Constants*
const int pResistor = A0; // Photoresistor at Arduino analog pin A0
const int ledPin=1; // Led pin at Arduino pin D1
pinMode(ledPin, OUTPUT); // Set lepPin - 1 pin as an output
pinMode(pResistor, INPUT);// Set pResistor - A0 pin as an input (optional)
Serial.begin(9600);
long sum;
int value; // Store value from photoresistor (0-1023)
int threshold;
int x;
int avg;
int len = sizeof(value);
float average (long * value,int len); // assuming array is int. - sum = 0L ; // sum will be larger than an item, long for safety.*
- for (int i = 0 ; i < len ; i++)*
- {*
_ sum = sum + value ;_
* return ((float) sum) / len ; // average will be fractional, so float may be appropriate.*
}}
}}
void loop(){
* value = analogRead(pResistor);*
* Serial.println(value);*
* //You can change value "25"*
* if (value < threshold){*
* digitalWrite(ledPin, HIGH); //Turn led on*
* }*
* else{*
* digitalWrite(ledPin, LOW); //Turn led off*
* }*
* delay(10); //Small delay*
}