-
Notifications
You must be signed in to change notification settings - Fork 73
/
LEDGoShooty.ino
49 lines (40 loc) · 1.01 KB
/
LEDGoShooty.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <Wire.h>
#include "Adafruit_TCS34725.h"
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
int relay = 10;
void setup() {
// Pin for relay module set as output
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
Serial.begin(9600);
if (tcs.begin())
{
Serial.println("Found sensor");
tcs.setInterrupt(true); // turn off LED
}
else
{
Serial.println("No TCS34725 found ... check your connections");
while (1); // halt!
}
}
void loop() {
digitalWrite(relay, LOW);
float red, green, blue;
delay(60); // takes 50ms to read
tcs.getRGB(&red, &green, &blue);
Serial.print("R:\t"); Serial.print(int(red));
Serial.print("\tG:\t"); Serial.print(int(green));
Serial.print("\tB:\t"); Serial.print(int(blue));
Serial.print("\n");
if ( int(red) >= 210 )
{
// Fire the relay
digitalWrite(relay, HIGH);
Serial.println("ON");
delay(50);
digitalWrite(relay, LOW);
Serial.println("OFF");
delay(50);
}
}