forked from ated4kids/rover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensoreColore.ino
149 lines (138 loc) · 3.32 KB
/
sensoreColore.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
[code]
#define VCC 12
#define OUT 10
#define S2 8
#define S3 9
#define S0 6
#define S1 7
#define Filters_R 0
#define Filters_G 1
#define Filters_B 2
long count = 0;
int counter = 0;
int G_flag = 1;
int RGB = 0;
float scaleFactor[3];
/******************************************
* IMPORTANT - Make sure you calibrate
* your sensor for White Balance initially
* e.g. place your TCS3200 in front
* of a piece of white paper
*******************************************/
void setup()
{
pinMode(OUT, INPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
digitalWrite(S2, HIGH);
digitalWrite(S3, LOW);
digitalWrite(S0, LOW); // OUTPUT FREQUENCY SCALING 2%
digitalWrite(S1, HIGH);
Serial.begin(9600);
Serial.println("Starting...");
digitalWrite(VCC, HIGH);
delay(100);
for(int i=0; i<3; i++)
{
Select_Filters(i);
int lastDigitalRead = HIGH;
for(int j=0; j<20000; j++)
{
int digitalReadValue = digitalRead(OUT);
if (lastDigitalRead == LOW && digitalReadValue == HIGH)
{
count++;
}
counter++;
lastDigitalRead = digitalReadValue;
}
scaleFactor[i] = 255.0/count;
Serial.print("count: ");
Serial.println(count);
Serial.print("counter: ");
Serial.println(counter);
Serial.print("scaleFactor: ");
Serial.println(scaleFactor[i],9);
counter=0;
count=0;
}
digitalWrite(VCC, LOW);
}
void loop()
{
Serial.println("loop");
digitalWrite(VCC, HIGH);
delay(100);
for(int i=0; i<3; i++)
{
RGB=i;
Select_Filters(i);
count=0;
int lastDigitalRead = HIGH;
for(int j=0; j<20000; j++)
{
int digitalReadValue = digitalRead(OUT);
if (lastDigitalRead == LOW && digitalReadValue == HIGH)
{
count++;
}
counter++;
lastDigitalRead = digitalReadValue;
}
Serial.print("value: ");
Serial.println(scaleFactor[i]*count);
Serial.print("counter ");
Serial.println(counter);
counter=0;
count=0;
}
digitalWrite(VCC, LOW);
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
digitalWrite(S0, LOW);
digitalWrite(S1, LOW);
delay(6000);
digitalWrite(S1, HIGH);
}
void Select_Filters(int RGB)
{
switch(RGB)
{
case Filters_R: //Red
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
Serial.println("-----select Red color");
break;
case Filters_G: //Green
digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
Serial.println("-----select Green color");
break;
case Filters_B: //Blue
digitalWrite(S2, LOW);
digitalWrite(S3, HIGH);
Serial.println("-----select Blue color");
break;
default: //Clear(no filter)
digitalWrite(S2, HIGH);
digitalWrite(S3, LOW);
Serial.println("-----no filter");
break;
}
}
[/code]