10
10
three 10 kilohm resistors
11
11
3 220 ohm resistors
12
12
3 photoresistors
13
- red green aand blue colored gels
13
+ red green and blue colored gels
14
14
15
15
Created 13 September 2012
16
+ Modified 14 November 2012
16
17
by Scott Fitzgerald
17
18
Thanks to Federico Vanzati for improvements
18
19
@@ -42,42 +43,42 @@ void setup() {
42
43
Serial.begin (9600 );
43
44
44
45
// set the digital pins as outputs
45
- pinMode (greenLedPin ,OUTPUT);
46
- pinMode (redLedPin ,OUTPUT);
47
- pinMode (blueLedPin ,OUTPUT);
46
+ pinMode (greenLEDPin ,OUTPUT);
47
+ pinMode (redLEDPin ,OUTPUT);
48
+ pinMode (blueLEDPin ,OUTPUT);
48
49
}
49
50
50
51
void loop () {
51
52
// Read the sensors first:
52
53
53
54
// read the value from the red-filtered photoresistor:
54
- redsensorValue = analogRead (redsensorPin );
55
+ redSensorValue = analogRead (redSensorPin );
55
56
// give the ADC a moment to settle
56
57
delay (5 );
57
58
// read the value from the green-filtered photoresistor:
58
- greensensorValue = analogRead (greensensorPin );
59
+ greenSensorValue = analogRead (greenSensorPin );
59
60
// give the ADC a moment to settle
60
61
delay (5 );
61
62
// read the value from the blue-filtered photoresistor:
62
- bluesensorValue = analogRead (bluesensorPin );
63
+ blueSensorValue = analogRead (blueSensorPin );
63
64
64
65
// print out the values to the serial monitor
65
66
Serial.print (" raw sensor Values \t red: " );
66
- Serial.print (redsensorValue );
67
+ Serial.print (redSensorValue );
67
68
Serial.print (" \t green: " );
68
- Serial.print (greensensorValue );
69
+ Serial.print (greenSensorValue );
69
70
Serial.print (" \t Blue: " );
70
- Serial.println (bluesensorValue );
71
+ Serial.println (blueSensorValue );
71
72
72
73
/*
73
74
In order to use the values from the sensor for the LED,
74
75
you need to do some math. The ADC provides a 10-bit number,
75
76
but analogWrite() uses 8 bits. You'll want to divide your
76
77
sensor readings by 4 to keep them in range of the output.
77
78
*/
78
- redValue = redsensorValue /4 ;
79
- greenValue = greensensorValue /4 ;
80
- blueValue = bluesensorValue /4 ;
79
+ redValue = redSensorValue /4 ;
80
+ greenValue = greenSensorValue /4 ;
81
+ blueValue = blueSensorValue /4 ;
81
82
82
83
// print out the mapped values
83
84
Serial.print (" Mapped sensor Values \t red: " );
@@ -90,8 +91,8 @@ void loop() {
90
91
/*
91
92
Now that you have a usable value, it's time to PWM the LED.
92
93
*/
93
- analogWrite (redLedPin , redValue);
94
- analogWrite (greenLedPin , greenValue);
95
- analogWrite (blueLedPin , blueValue);
94
+ analogWrite (redLEDPin , redValue);
95
+ analogWrite (greenLEDPin , greenValue);
96
+ analogWrite (blueLEDPin , blueValue);
96
97
}
97
98
0 commit comments