#include #include "Adafruit_TCS34725.h" #include #define PIN_NEOPIXEL 7 #define NUM_PIXELS 1 Adafruit_NeoPixel strip(NUM_PIXELS, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800); Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_600MS, TCS34725_GAIN_1X); void setup() { Serial.begin(9600); strip.begin(); strip.setBrightness(255); // Ciclo de prueba al arrancar strip.setPixelColor(0, strip.Color(255, 0, 0)); strip.show(); delay(400); strip.setPixelColor(0, strip.Color(0, 255, 0)); strip.show(); delay(400); strip.setPixelColor(0, strip.Color(0, 0, 255)); strip.show(); delay(400); strip.setPixelColor(0, strip.Color(0, 0, 0)); strip.show(); if (!tcs.begin()) { Serial.println("ERROR: Sensor no encontrado"); while(1); } Serial.println("Sensor OK - Acerca objetos verdes"); } void loop() { uint16_t r, g, b, c; tcs.getRawData(&r, &g, &b, &c); uint8_t rN = 0, gN = 0, bN = 0; if (c > 50) { float escala = 255.0 / max(r, max(g, b)); rN = constrain((uint16_t)(r * escala), 0, 255); gN = constrain((uint16_t)(g * escala), 0, 255); bN = constrain((uint16_t)(b * escala), 0, 255); rN = constrain((int)(rN - 50) * 3, 0, 255); gN = constrain((int)(gN - 50) * 3, 0, 255); bN = constrain((int)(bN - 50) * 3, 0, 255); } // Verde dominante: G supera a R y B bool esVerde = (gN > rN * 1.2) && (gN > bN * 1.2) && (gN > 40); if (esVerde) { String tono = clasificarVerde(rN, gN, bN); // Mostrar el color EXACTO detectado en el NeoPixel strip.setPixelColor(0, strip.Color(rN, gN, bN)); strip.show(); Serial.print("VERDE - "); Serial.print(tono); Serial.print(" | R:"); Serial.print(rN); Serial.print(" G:"); Serial.print(gN); Serial.print(" B:"); Serial.println(bN); } else { // No es verde: apagar NeoPixel strip.setPixelColor(0, strip.Color(0, 0, 0)); strip.show(); Serial.println("No es verde"); } delay(500); } String clasificarVerde(uint8_t r, uint8_t g, uint8_t b) { // --- Por intensidad (oscuro / medio / claro) --- // usando el canal G como referencia de intensidad // Verde muy oscuro (casi negro) if (g < 60) return "Verde muy oscuro"; // Verde oscuro (bosque, pino) if (g < 120 && r < 60 && b < 60) return "Verde oscuro"; // Verde oliva (G y R medios, B bajo — tono apagado/terroso) if (g >= 60 && r >= 60 && r < 180 && b < 60) return "Verde oliva"; // Verde puro (G alto, R y B bajos) if (g > 180 && r < 80 && b < 80) return "Verde puro"; // Verde lima (G alto + bastante R, tirando a amarillo) if (g > 150 && r > 100 && b < 80) return "Verde lima"; // Verde menta (G alto + algo de B, fresco/claro) if (g > 150 && b > 80 && b < 160 && r < 100) return "Verde menta"; // Verde agua / turquesa (G y B altos, R bajo) if (g > 120 && b > 120 && r < 80) return "Verde agua"; // Verde claro / pastel if (g > 150 && r > 80 && b > 80) return "Verde claro"; return "Verde"; }