Hey,
I've tried changing the variables from 'int' to 'unsigned int' and 'long' and there is no visible difference all outputs are identical. The results show the value of var average which I want to print to serial and use as a value of luminosity for my led. See the serial results here:
-28
-28
-29
-27
-30
-27
-28
-30
-30
-30
-30
-29
-30
-30
-30
-30
-30
-26
-28
(this is where I shined a torch at the LDR)
29
29
-11
-10
1
21
27
26
23
20
27
25
22
22
(this is where I took the tortch away)
-13
-13
2
-29
-28
-30
-28
-27
-30
I spammed the Serial.println() function in order to see whats inside each variable each loop and the results may explain the calculated negative numbers. Here are the results (key below):
Start total: 0
Start index: 0
RAW: 30
Output average: 0
Start total: 0
Start index: 0
RAW: 30
Output average: 0
Start total: 0
Start index: 0
RAW: 30
Output average: 0
Start total: 0
Start index: 0
RAW: 30
Output average: 0
Start total: 0
Start index: 0
RAW: 30
Output average: 0
Key:
Start total = the value of var total at the start of each loop
Start index = the value of var 'readIndex' at the start of each loop (should be progressing to 10 and resetting to 0, rinse and repeat)
RAW = the value outputted from the sensor
Output average = the value I want to display
My program isn't passing the data like it should be. Maybe returning multiple variables isn't ideal?