For some reason the average value of the orange light isnt working properly when I have high values of light, but works really well with low values of light for some reason
#include <Wire.h>
#include "Adafruit_AS726x.h"
//create the object
Adafruit_AS726x ams;
//buffer to hold raw values
uint16_t sensorValues[AS726x_NUM_CHANNELS];
//buffer to hold calibrated values (not used by default in this example)
//float calibratedValues[AS726x_NUM_CHANNELS];
int numReads = 10;
int cont;
int sensor;
float sum;
float average;
int pinoRed = 9; //PINO DIGITAL UTILIZADO PELO TERMINAL VERMELHO
int pinoGreen = 10; //PINO DIGITAL UTILIZADO PELO TERMINAL VERDE
int pinoBlue = 11; //PINO DIGITAL UTILIZADO PELO TERMINAL AZUL
int val; //VARIÁVEL DO TIPO INTEIRA
void setup() {
Serial.begin(9600);
while(!Serial);
pinMode(pinoRed, OUTPUT); //DEFINE O PINO COMO SAÍDA
pinMode(pinoBlue, OUTPUT); //DEFINE O PINO COMO SAÍDA
pinMode(pinoGreen, OUTPUT); //DEFINE O PINO COMO SAÍDA
analogWrite(pinoRed, 255); //PINO RECEBE O VALOR
analogWrite(pinoGreen, 223); //PINO RECEBE O VALOR
analogWrite(pinoBlue, 0); //PINO RECEBE O VALOR
delay (10); //INTERVALO DE 10 MILISSEGUNDOS
//initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
//begin and make sure we can talk to the sensor
if(!ams.begin()){
Serial.println("could not connect to sensor! Please check your wiring.");
while(1);
}
do {
//read the device temperature
//uint8_t temp = ams.readTemperature();
//ams.drvOn(); //uncomment this if you want to use the driver LED for readings
ams.startMeasurement(); //begin a measurement
//wait till data is available
bool rdy = false;
while(!rdy){
delay(1000);
rdy = ams.dataReady();
}
//ams.drvOff(); //uncomment this if you want to use the driver LED for readings
//read the values!
ams.readRawValues(sensorValues);
//ams.readCalibratedValues(calibratedValues);
for (int k = 0; k < numReads; k++){
sensor = sensorValues[AS726x_ORANGE];
sum += sensor;
}
//Serial.print("Temp: "); Serial.print(temp);
//Serial.print(" Violet: "); Serial.print(sensorValues[AS726x_VIOLET]);
//Serial.print(" Blue: "); Serial.print(sensorValues[AS726x_BLUE]);
//Serial.print(" Green: "); Serial.print(sensorValues[AS726x_GREEN]);
//Serial.print(" Yellow: "); Serial.print(sensorValues[AS726x_YELLOW]);
Serial.print(" Orange: "); Serial.print(sensorValues[AS726x_ORANGE]);
//Serial.print(" Red: "); Serial.print(sensorValues[AS726x_RED]);
Serial.println();
Serial.println();
cont++;
} while(cont < numReads);
average = sum/(numReads*10);
Serial.print(" Orange Average: "); Serial.print(average);
}
void loop() {
}


