Skip to content

Instantly share code, notes, and snippets.

@jasonnerothin
Created November 6, 2017 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonnerothin/93c5d1a66d356aac1ebd658353c5abdf to your computer and use it in GitHub Desktop.
Save jasonnerothin/93c5d1a66d356aac1ebd658353c5abdf to your computer and use it in GitHub Desktop.
// constants
const int greenLEDPin = 9;
const int redLEDPin = 11;
const int blueLEDPin = 10;
const int redSensorPin = A0;
const int greenSensorPin = A0;
const int blueSensorPin = A0;
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() {
redSensorValue = analogRead(redSensorPin);
greenSensorValue = analogRead(greenSensorPin);
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.print(blueSensorValue);
redValue = redValue/4;
greenValue = greenValue/4;
blueValue = blueValue/4;
Serial.print("Mapped Sensor Values: \t Red:");
Serial.print(redValue);
Serial.print("\t Green: ");
Serial.print(greenValue);
Serial.print("\t Blue: ");
Serial.print(blueValue);
analogWrite(redLEDPin, redValue);
analogWrite(greenLEDPin, greenValue);
analogWrite(blueLEDPin, blueValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment