- #include <Wire.h>
- #include "Adafruit_TCS34725.h"
- #include <Servo.h>
- Servo myservo; // create servo object to control a servo
- // twelve servo objects can be created on most boards
- int pos = 0; // variable to store the servo position
- /* Example code for the Adafruit TCS34725 breakout library */
- /* Connect SCL to analog 5
- Connect SDA to analog 4
- Connect VDD to 3.3V DC
- Connect GROUND to common ground */
- /* Initialise with default values (int time = 2.4ms, gain = 1x) */
- // Adafruit_TCS34725 tcs = Adafruit_TCS34725();
- /* Initialise with specific int time and gain values */
- Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_614MS, TCS34725_GAIN_1X);
- void setup(void) {
- Serial.begin(9600);
- if (tcs.begin()) {
- Serial.println("Found sensor");
- } else {
- Serial.println("No TCS34725 found ... check your connections");
- while (1);
- }
- myservo.attach(9); // attaches the servo on pin 9 to the servo object
- // Now we're ready to get readings!
- }
- void loop(void) {
- uint16_t r, g, b, c;
- tcs.setIntegrationTime(TCS34725_INTEGRATIONTIME_614MS);
- delay(154); // Delay for one old integ. time period (to finish old reading)
- delay(615); // Delay for one new integ. time period (to allow new reading)
- tcs.getRawData(&r, &g, &b, &c);
- Serial.print("Integ. time: 614.4ms ");
- Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
- Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
- Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
- Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
- Serial.println(" ");
- tcs.setIntegrationTime(TCS34725_INTEGRATIONTIME_300MS);
- delay(615); // Delay for one old integ. time period (to finish old reading)
- delay(300); // Delay for one new integ. time period (to allow new reading)
- tcs.getRawData(&r, &g, &b, &c);
- Serial.print("Integ. time: 300.0ms ");
- Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
- Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
- Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
- Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
- Serial.println(" ");
- tcs.setIntegrationTime(TCS34725_INTEGRATIONTIME_154MS);
- delay(300); // Delay for one old integ. time period (to finish old reading)
- delay(154); // Delay for one new integ. time period (to allow new reading)
- tcs.getRawData(&r, &g, &b, &c);
- Serial.print("Integ. time: 153.6ms ");
- Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
- Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
- Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
- Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
- Serial.println(" ");
- //red
- if(r < 500 && g > r && r > b) {
- myservo.write(15);
- } else if(g > 1000 && g > r && g > b){
- //Green
- myservo.write(110);
- } else if(b > 1000 && b > g && b > r)
- {
- myservo.write(30);}
- else if(b > 1000 && g > 1000 && r > 1000) {
- //white
- myservo.write(45);}
- else if(r > 1000 && g > 500 && r < 200){
- //orange
- myservo.write(60);} else if(r > 1000 && g > 1000 && b < 200){
- //Yellow
- myservo.write(75);}
- else {
- myservo.write(90);}
- /*while (r, DEC < 100)
- {
- if (pos <= 72) { // goes from 0 degrees to 180 degrees
- // in steps of 1 degree
- pos += 1;
- myservo.write(pos); // tell servo to go to position in variable 'pos'
- delay(15); // waits 15ms for the servo to reach the position
- }
- else if(pos >= 72) { // goes from 180 degrees to 0 degrees
- pos -= 1;
- myservo.write(pos); // tell servo to go to position in variable 'pos'
- delay(15); // waits 15ms for the servo to reach the position
- }
- }*/
- }
[text] arduino
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new:
File Description
- arduino
- Paste Code
- 05 Jun-2023
- 3.78 Kb
You can Share it: