0% found this document useful (0 votes)
22 views2 pages

Codigo Del Selector5555

This document contains code for an Arduino project that uses a color sensor to detect the color being sensed and control servo motors based on the detected color. It includes libraries for the color sensor and converting RGB values to HSV values. It defines servo objects, reads color data from the sensor, converts to HSV, prints the detected color name, and writes positions to the servos based on the detected color.

Uploaded by

Maria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Codigo Del Selector5555

This document contains code for an Arduino project that uses a color sensor to detect the color being sensed and control servo motors based on the detected color. It includes libraries for the color sensor and converting RGB values to HSV values. It defines servo objects, reads color data from the sensor, converts to HSV, prints the detected color name, and writes positions to the servos based on the detected color.

Uploaded by

Maria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy