really really thanks for your attention, sincerely!!
Here the sketch:
/* CODE TO CONTROL THE COLOR PICKER */
/* Connect SCL to analog 5
Connect SDA to analog 4
Connect VDD to 3.3V DC
Connect GROUND to common ground */
/* INCLUDING THE LIBRARIES */
#include <Wire.h>;
#include <Adafruit_TCS34725.h>; /* TCS34725 Color Sensor Library */
#include <DFRobot_RGBLCD1602.h>; /* DFrobot Display Library */
#include <BasicLinearAlgebra.h>; /* library to calculate the calibration matrix */
/* VARIABLES DECLARATION */
char comando;
char read = 1;
int data;
unsigned long r; /* Declaring the red, green and blue values unsigned long variables */
unsigned long g;
unsigned long b;
unsigned long c;
unsigned long red01;
unsigned long green01;
unsigned long blue01;
double red_normalized;
double green_normalized;
double blue_normalized;
double red_calibrated;
double green_calibrated;
double blue_calibrated;
unsigned long multiplier;
unsigned long factor;
int red_rounded;
int green_rounded;
int blue_rounded;
/* SPECIFYING THAT WE ARE USING THE NAMESPACE BLA */
using namespace BLA;
/* PERIPHERALS INITIALIZATION */
/* TCS34725 definition with default values (integration time= 2.4 ms and gain = 1x) */
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_614MS, TCS34725_GAIN_1X);
/* DFRobot definition (16 characters and two rows) */
DFRobot_RGBLCD1602 lcd(/*RGBAddr*/ 0x60, /*lcdCols*/ 16, /*lcdRows*/ 2);
/* */
void setup(void) {
Serial.begin(9600); /* opening of the serial port and setting the data rata to 9600 */
/* Initializating the display DFRobot */
lcd.init();
/* Checking and warning if the connections of the sensor are right or not.
If that condition gives value 1, the connections are correct,
otherwise the wiring needs to be controlled */
if (tcs.begin()) {
Serial.println("Found TCS34725");
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1)
;
}
}
/* Starting to get the red, green, blue and clear values */
void loop(void) {
uint16_t r, g, b, c; /* Defining red, green and blue as variables */
/* NORMALIZING TO THE CLEAR THE r, g, b VALUES */
multiplier = 255;
factor = multiplier * 1000000 / c;
red01 = factor * r;
green01 = factor * g;
blue01 = factor * b;
red_normalized = red01 / 1000000;
green_normalized = green01 / 1000000;
blue_normalized = blue01 / 1000000;
/* CALIBRATING THE NORMALIZED VALUES */
BLA::Matrix<3, 3> M = { 1.5740, -0.1524, -0.1751, -0.4020, 1.5593, -0.4360, -0.1184, 0.0212, 1.0005 }; /* declaring the matrix A 3 rows and 3 columns */
BLA::Matrix<3, 1> v = { red_normalized, green_normalized, blue_normalized }; /* declaring the column vector */
BLA::Matrix<3, 1> D = M * v; /* moltiplication of the calibration matrix with the data from the sensor */
red_calibrated = D(0);
green_calibrated = D(1);
blue_calibrated = D(2);
/* Rounding the calibrated values */
red_rounded = round(red_calibrated);
green_rounded = round(green_calibrated);
blue_rounded = round(blue_calibrated);
if (read) {
tcs.getRawData(&r, &g, &b, &c); /* getting the data from the TCS34725 */
Serial.print("Red: ");
Serial.print(red_rounded, DEC);
Serial.print(" ");
Serial.print("Green: ");
Serial.print(green_rounded, DEC);
Serial.print(" ");
Serial.print("Blue: ");
Serial.print(blue_rounded, DEC);
Serial.print(" ");
Serial.print("Clear: ");
Serial.print(c, DEC);
Serial.print(" ");
Serial.println(" ");
/* setting the Red, Green and Blue values to the Backlight of DFRobot */
lcd.setRGB(red_rounded, green_rounded, blue_rounded);
showDataLCD();
}
if (Serial.available() > 0) {
comando = Serial.read();
switch (comando) {
case 'R':
tcs.getRawData(&r, &g, &b, &c); /* getting the data from the TCS34725 */
Serial.print("Red: ");
Serial.print(red_rounded, DEC);
Serial.print(" ");
Serial.print("Green: ");
Serial.print(green_rounded, DEC);
Serial.print(" ");
Serial.print("Blue: ");
Serial.print(blue_rounded, DEC);
Serial.print(" ");
Serial.print("Clear: ");
Serial.print(c, DEC);
Serial.print(" ");
Serial.println(" ");
/* setting the Red, Green and Blue values to the Backlight of DFRobot */
lcd.setRGB(red_rounded, green_rounded, blue_rounded);
break;
case 'W':
data = Serial.parseInt();
break;
case 'G':
comando = Serial.read();
tcs.setGain(comando);
break;
case 'C':
read = 1;
break;
case 'S':
read = 0;
break;
}
}
}
/* Showing the calibrated data in the DFRobot RGB 1602 display */
void showDataLCD(void) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("R");
lcd.print(red_rounded);
lcd.setCursor(6, 0);
lcd.print("G");
lcd.print(green_rounded);
lcd.setCursor(12, 0);
lcd.print("B");
lcd.print(blue_rounded);
lcd.setCursor(0, 1);
lcd.print("Color Picker");
delay(2000);
}
and here the error message
F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\Aveiro02\Aveiro02.ino:21:6: error: 'char read' redeclared as different kind of symbol
char read = 1;
^~~~
In file included from C:\Users\MSI\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\4.2.1\cores\arduino/mbed/platform/include/platform/platform.h:26:0,
from C:\Users\MSI\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\4.2.1\cores\arduino/mbed/platform/include/platform/FileHandle.h:25,
from C:\Users\MSI\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\4.2.1\cores\arduino/macros.h:41,
from C:\Users\MSI\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\4.2.1\variants\NANO_RP2040_CONNECT/pins_arduino.h:2,
from C:\Users\MSI\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\4.2.1\cores\arduino/Arduino.h:76,
from C:\Users\MSI\AppData\Local\arduino\sketches\9A95C6BF0A26362DC92A72CB82C31D46\sketch\Aveiro02.ino.cpp:1:
C:\Users\MSI\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\4.2.1\cores\arduino/mbed/platform/include/platform/mbed_retarget.h:740:13: note: previous declaration 'ssize_t read(int, void*, size_t)'
ssize_t read(int fildes, void *buf, size_t nbyte);
^~~~
F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\Aveiro02\Aveiro02.ino: In function 'void loop()':
F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\Aveiro02\Aveiro02.ino:193:28: error: invalid conversion from 'char' to 'tcs34725Gain_t' [-fpermissive]
tcs.setGain(comando);
^
In file included from F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\Aveiro02\Aveiro02.ino:12:0:
C:\Users\MSI\Documents\Arduino\libraries\Adafruit_TCS34725/Adafruit_TCS34725.h:205:8: note: initializing argument 1 of 'void Adafruit_TCS34725::setGain(tcs34725Gain_t)'
void setGain(tcs34725Gain_t gain);
^~~~~~~
F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\Aveiro02\Aveiro02.ino:196:16: error: assignment of function 'ssize_t read(int, void*, size_t)'
read = 1;
^
F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\Aveiro02\Aveiro02.ino:196:16: error: cannot convert 'int' to 'ssize_t(int, void*, size_t) {aka int(int, void*, unsigned int)}' in assignment
F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\Aveiro02\Aveiro02.ino:200:16: error: assignment of function 'ssize_t read(int, void*, size_t)'
read = 0;
^
F:\Users\Caterina\Desktop\Dati\Lisbona\Lavoro sperimentale\Parte elettronica\Color Picker migliorato\Aveiro02\Aveiro02.ino:200:16: error: cannot convert 'int' to 'ssize_t(int, void*, size_t) {aka int(int, void*, unsigned int)}' in assignment
exit status 1
Compilation error: 'char read' redeclared as different kind of symbol