forked from jtrudeau/dawsonhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColor_RGB_Sensor.ino
More file actions
90 lines (52 loc) · 1.24 KB
/
Color_RGB_Sensor.ino
File metadata and controls
90 lines (52 loc) · 1.24 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//Tawfiq Jawhar
//Dawson Hackathon 2019
//Color RGB Sensor sample code
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 9
int redFrequency = 0;
int greenFrequency =0;
int blueFrequency=0;
void setup() {
// put your setup code here, to run once:
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(sensorOut, INPUT);
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
redFrequency = pulseIn(sensorOut, LOW);
Serial.print(redFrequency);
Serial.print(" ");
delay(100);
digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
greenFrequency = pulseIn(sensorOut, LOW);
Serial.print(greenFrequency);
Serial.print(" ");
delay(100);
digitalWrite(S2, LOW);
digitalWrite(S3, HIGH);
blueFrequency = pulseIn(sensorOut, LOW);
Serial.print(blueFrequency);
Serial.print("\n");
delay(100);
//479 1064 1050
//696 1572 1563
//651.5 1496 1457
//635.7 1453 1427.35
if(redFrequency >= 470 && redFrequency <= 700)
Serial.print("RED\n");
else
Serial.print("NOT RED\n");
delay(1000);
}