Sensor de cor RGB TCS34725





/* Este código serve para usar dois sensores de cor RGB no mesmo Arduino em outras portas que não sejam as de padrão SDA SDL. Créditos a equipe Alpha Robot do LIA - Laboratório de Inteligência Artificial. IFAC - Campus Tarauacá*/

#include <Wire.h>
#include "Adafruit_TCS34725softi2c.h"

// You can use any digital pin for emulate SDA / SCL
#define SDApin_1 15
#define SCLpin_1 14

#define SDApin_2 19
#define SCLpin_2 18

// for a common anode LED, connect the common pin to +5V
// for common cathode, connect the common to ground

// set to false if using a common cathode LED
#define commonAnode_1 true
#define commonAnode_2 true

// our RGB -> eye-recognized gamma color
byte gammatable_1[256];
byte gammatable_2[256];

Adafruit_TCS34725softi2c tcs_1 = Adafruit_TCS34725softi2c(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X, SDApin_1, SCLpin_1);
Adafruit_TCS34725softi2c tcs_2 = Adafruit_TCS34725softi2c(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X, SDApin_2, SCLpin_2);

void setup() {
  Serial.begin(9600);
  Serial.println("Color View Test!");

  if (tcs_1.begin()) {
    Serial.println("Found sensor 1");
  } else {
    Serial.println("No TCS34725 (numero 1) found ... check your connections");
    while (1); // halt!
  }

  if (tcs_2.begin()) {
    Serial.println("Found sensor 2");
  } else {
    Serial.println("No TCS34725 (numero 2) found ... check your connections");
    while (1); // halt!
  }

  // use these three pins to drive an LED


  // thanks PhilB for this gamma table!
  // it helps convert RGB colors to what humans see
  for (int i=0; i<256; i++) {
    float x = i;
    x /= 255;
    x = pow(x, 2.5);
    x *= 255;
   
    if (commonAnode_1) {
      gammatable_1[i] = 255 - x;
    } else {
      gammatable_1[i] = x;   
    }
 
    }


    for (int i=0; i<256; i++) {
    float x = i;
    x /= 255;
    x = pow(x, 2.5);
    x *= 255;
   
    if (commonAnode_2) {
      gammatable_2[i] = 255 - x;
    } else {
      gammatable_2[i] = x;   
    }
 
    }
   
    //Serial.println(gammatable[i]);



}
void loop()
{
  uint16_t clear, red_1,green_1, blue_1;
  uint16_t red_2,green_2, blue_2;


  tcs_1.setInterrupt(false);      // turn on LED
  tcs_2.setInterrupt(false);      // turn on LED

  delay(60);  // takes 50ms to read

  tcs_1.getRawData(&red_1, &green_1, &blue_1, &clear);
  tcs_2.getRawData(&red_2, &green_2, &blue_2, &clear);



  tcs_1.setInterrupt(true);  // turn off LED
  tcs_2.setInterrupt(true);  // turn off LED


  Serial.print("\tG(1):\t"); Serial.print(green_1);
  Serial.println();


  Serial.print("\tG(2):\t"); Serial.print(green_2);
  Serial.println();



delay(500);
}

Comentários

Postar um comentário

Postagens mais visitadas deste blog

Sensor de Distância ultra-sônico e Arduino

Código: Seguir Linha