Color Mixing Lamp
Color Mixing Lamp Modified
const int greenLEDPin = 9; // pin 9
const int redLEDPin = 10; // pin 10
const int blueLEDPin = 11; // pin 11
const int redSensorPin = A0; // pin photoresistor = A0;
const int greenSensorPin = A1; // pin photoresistor = A1;
const int blueSensorPin = A2; // pin photoresistor = A2;
int redValue = 0;
int greenValue = 0;
int blueValue = 0;
int redSensorValue = 0;
int greenSensorValue = 0;
int blueSensorValue = 0;
void setup() {
Serial.begin(9600);
pinMode(greenLEDPin, OUTPUT);
pinMode(redLEDPin, OUTPUT);
pinMode(blueLEDPin, OUTPUT);
}
void loop() {
digitalWrite(redSensorValue, HIGH);
delay(500);
digitalWrite(redSensorValue, LOW);
delay(500);
redSensorValue = analogRead(redSensorPin);
delay(5);
greenSensorValue = analogRead(greenSensorPin);
delay(5);
blueSensorValue = analogRead(blueSensorPin);
Serial.print("raw sensor Values \t red: ");
Serial.print(redSensorValue);
Serial.print("\t green: ");
Serial.print(greenSensorValue);
Serial.print("\t Blue: ");
Serial.println(blueSensorValue);
redValue = redSensorValue / 4;
greenValue = greenSensorValue / 4;
blueValue = blueSensorValue / 4;
Serial.print("Mapped sensor Values \t red: ");
Serial.print(redValue);
Serial.print("\t green: ");
Serial.print(greenValue);
Serial.print("\t Blue: ");
Serial.println(blueValue);
analogWrite(redLEDPin, redValue);
analogWrite(greenLEDPin, greenValue);
analogWrite(blueLEDPin, blueValue);
}
// I have just created a sensor of movement by accident. It works like this:
// After modifying the code to blink, when you pass by the sensors, it will capture the light change
// The blue will blink if you are moving from the left side (shadows hitting from the left side)
// The red light will blink if you are moving from the right side
// the green light will blink if the movements come from above the sensor
// for that to happen, the sensors have to be placed as shown in the book
const int greenLEDPin = 9; // pin 9
const int redLEDPin = 10; // pin 10
const int blueLEDPin = 11; // pin 11
const int redSensorPin = A0; // pin photoresistor = A0;
const int greenSensorPin = A1; // pin photoresistor = A1;
const int blueSensorPin = A2; // pin photoresistor = A2;
int redValue = 0;
int greenValue = 0;
int blueValue = 0;
int redSensorValue = 0;
int greenSensorValue = 0;
int blueSensorValue = 0;
void setup() {
Serial.begin(9600);
pinMode(greenLEDPin, OUTPUT);
pinMode(redLEDPin, OUTPUT);
pinMode(blueLEDPin, OUTPUT);
}
void loop() {
digitalWrite(redSensorValue, HIGH);
delay(100);
digitalWrite(redSensorValue, LOW);
delay(100);
redSensorValue = analogRead(redSensorPin);
delay(2);
greenSensorValue = analogRead(greenSensorPin);
delay(2);
blueSensorValue = analogRead(blueSensorPin);
Serial.print("raw sensor Values \t red: ");
Serial.print(redSensorValue);
Serial.print("\t green: ");
Serial.print(greenSensorValue);
Serial.print("\t Blue: ");
Serial.println(blueSensorValue);
redValue = redSensorValue / 4;
greenValue = greenSensorValue / 4;
blueValue = blueSensorValue / 4;
Serial.print("Mapped sensor Values \t red: ");
Serial.print(redValue);
Serial.print("\t green: ");
Serial.print(greenValue);
Serial.print("\t Blue: ");
Serial.println(blueValue);
analogWrite(redLEDPin, redValue);
analogWrite(greenLEDPin, greenValue);
analogWrite(blueLEDPin, blueValue);
}