-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d9287a
commit 8d6ca1a
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} |