Fixed issue in Starter kit example number 4

This commit is contained in:
Scott 2012-11-14 16:07:38 -05:00
parent 4672d451c8
commit 20c181470d
1 changed files with 17 additions and 16 deletions

View File

@ -10,9 +10,10 @@
three 10 kilohm resistors
3 220 ohm resistors
3 photoresistors
red green aand blue colored gels
red green and blue colored gels
Created 13 September 2012
Modified 14 November 2012
by Scott Fitzgerald
Thanks to Federico Vanzati for improvements
@ -42,32 +43,32 @@ void setup() {
Serial.begin(9600);
// set the digital pins as outputs
pinMode(greenLedPin,OUTPUT);
pinMode(redLedPin,OUTPUT);
pinMode(blueLedPin,OUTPUT);
pinMode(greenLEDPin,OUTPUT);
pinMode(redLEDPin,OUTPUT);
pinMode(blueLEDPin,OUTPUT);
}
void loop() {
// Read the sensors first:
// read the value from the red-filtered photoresistor:
redsensorValue = analogRead(redsensorPin);
redSensorValue = analogRead(redSensorPin);
// give the ADC a moment to settle
delay(5);
// read the value from the green-filtered photoresistor:
greensensorValue = analogRead(greensensorPin);
greenSensorValue = analogRead(greenSensorPin);
// give the ADC a moment to settle
delay(5);
// read the value from the blue-filtered photoresistor:
bluesensorValue = analogRead(bluesensorPin);
blueSensorValue = analogRead(blueSensorPin);
// print out the values to the serial monitor
Serial.print("raw sensor Values \t red: ");
Serial.print(redsensorValue);
Serial.print(redSensorValue);
Serial.print("\t green: ");
Serial.print(greensensorValue);
Serial.print(greenSensorValue);
Serial.print("\t Blue: ");
Serial.println(bluesensorValue);
Serial.println(blueSensorValue);
/*
In order to use the values from the sensor for the LED,
@ -75,9 +76,9 @@ void loop() {
but analogWrite() uses 8 bits. You'll want to divide your
sensor readings by 4 to keep them in range of the output.
*/
redValue = redsensorValue/4;
greenValue = greensensorValue/4;
blueValue = bluesensorValue/4;
redValue = redSensorValue/4;
greenValue = greenSensorValue/4;
blueValue = blueSensorValue/4;
// print out the mapped values
Serial.print("Mapped sensor Values \t red: ");
@ -90,8 +91,8 @@ void loop() {
/*
Now that you have a usable value, it's time to PWM the LED.
*/
analogWrite(redLedPin, redValue);
analogWrite(greenLedPin, greenValue);
analogWrite(blueLedPin, blueValue);
analogWrite(redLEDPin, redValue);
analogWrite(greenLEDPin, greenValue);
analogWrite(blueLEDPin, blueValue);
}