-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor-mixing-lamp
53 lines (46 loc) · 1.77 KB
/
color-mixing-lamp
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
const int greenLEDPin = 9;
const int blueLEDPin = 10;
const int redLEDPin = 11;
//useful constants
const int redSensorPin = A0;
const int greenSensorPin = A1;
const int blueSensorPin = A2;
int redValue = 0;
int greenValue = 0;
int blueValue = 0;
//variables to store the sensor readings as well as the light level of each LED
int redSensorValue = 0;
int greenSensorValue = 0;
int blueSensorValue = 0;
void setup(){
Serial.begin(9600);
//setting the direction of the digital pins and setting up the serial port
pinMode(greenLEDPin, OUTPUT);
pinMode(blueLEDPin, OUTPUT);
pinMode(redLEDPin,OUTPUT);
}
void loop(){
redSensorValue = analogRead(redSensorValue);
delay(5); //reading the vlaue of each light sensor
greenSensorValue = analogRead(greenSensorValue);
delay(5);
blueSensorValue = analogRead(blueSensorValue);
Serial.print("Raw Sensor Value \t Red:");
Serial.print(redSensorValue);
Serial.print("\t Green:"); //report the sensor readings to the computer
Serial.print(greenSensorValue);
Serial.print("\t Blue:");
Serial.print(blueSensorValue);
redValue = redSensorValue/4;
greenValue = greenSensorValue/4; //Convert the sensor readings from a value between 0 - 1023
blueValue = blueSensorValue/4; //to a value between 0 - 255
Serial.print("Mapped Sensor Values \t Red:");
Serial.print(redValue);
Serial.print(" \t Green:"); //report the calculated LED light levels
Serial.print(greenValue);
Serial.print("\t Blue:");
Serial.print(blueValue);
analogWrite(redLEDPin,redValue);
analogWrite(greenLEDPin, greenValue); //Set the LED light levels
analogWrite(blueLEDPin, blueValue);
}