You are on page 1of 2

#include <Servo.

h>
#include <Wire.h>
#include "Adafruit_TCS34725.h"
#include <ColorConverterLib.h>

Servo arriba;
Servo abajo;

int pos = 90;

Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS,


TCS34725_GAIN_4X);

void setup() {
arriba.attach(3);
abajo.attach(5);

Serial.begin(9600);

if (!tcs.begin())
{

void loop() {

uint16_t clear, red, green, blue;


tcs.setInterrupt(false);
delay(60); // Cuesta 50ms capturar el color
tcs.getRawData(&red, &green, &blue, &clear);
tcs.setInterrupt(true);

// Hacer rgb medición relativa


uint32_t sum = clear;
float r, g, b;
r = red; r /= sum;
g = green; g /= sum;
b = blue; b /= sum;

// Escalar rgb a bytes


r *= 256; g *= 256; b *= 256;

// Convertir a hue, saturation, value


double hue, saturation, value;
RGBConverterLib::RgbToHsv(static_cast<uint8_t>(r), static_cast<uint8_t>(g),
static_cast<uint8_t>(b), hue, saturation, value);
}
void printColorName(double hue)
{
if (hue < 15)
{
Serial.println("Rojo");
if (pos = 90; pos <= 140; pos += 1) {
abajo.write(pos);
delay(15); }
if (pos = 45; pos <= 140; pos += 1) {
abajo.write(pos);
delay(15); }
if (pos = 140; pos >= 140; pos = 0) {
abajo.write(pos);
delay(15); }
}

else if (hue < 150)


{
Serial.println("Verde");
if (pos = 90; pos >= 45; pos -= 1) {
abajo.write(pos);
delay(15); }
if (pos = 140; pos >= 45; pos -= 1) {
abajo.write(pos);
delay(15); }
if (pos = 45; pos >= 45; pos = 0) {
abajo.write(pos);
delay(15); }
}

else if (hue < 270)


{
Serial.println("Azul");
if (pos = 45; pos <= 90; pos += 1) {
abajo.write(pos);
delay(15); }
if (pos = 140; pos >= 90; pos -= 1) {
abajo.write(pos);
delay(15) }
if (pos = 90; pos <= 90; pos = 0) {
abajo.write(pos);
delay(15); }
}

for (pos = 145; pos >= 110; pos -= 1) {


arriba.write(pos);
delay(15);
}
for (pos = 110; pos <= 35; pos -= 1) {
arriba.write(pos);
delay(15); }
for (pos = 35; pos <= 145; pos += 1) {
arriba.write(pos);
delay(15); }
}

You might also like