Question: Arduino SOFTPOTENTIOMETER. I am trying to modify the given code so that a buzzer goes off whenever the color specified (doesn't matter which) shows on
Arduino SOFTPOTENTIOMETER. I am trying to modify the given code so that a buzzer goes off whenever the color specified (doesn't matter which) shows on the RGB. Please code the modification in red so I can read it.
Code:
const int RED_LED_PIN = 9; // Red LED Pin const int GREEN_LED_PIN = 10; // Green LED Pin const int BLUE_LED_PIN = 11; // Blue LED Pin
const int SENSOR_PIN = 0; // Analog input pin
int redValue, greenValue, blueValue;
void setup() { }
void loop() { int sensorValue;
// Read the voltage from the softpot (0-1023)
sensorValue = analogRead(SENSOR_PIN);
setRGB(sensorValue); }
void setRGB(int RGBposition) { int mapRGB1, mapRGB2, constrained1, constrained2;
mapRGB1 = map(RGBposition, 0, 341, 255, 0); constrained1 = constrain(mapRGB1, 0, 255);
mapRGB2 = map(RGBposition, 682, 1023, 0, 255); constrained2 = constrain(mapRGB2, 0, 255);
redValue = constrained1 + constrained2;
greenValue = constrain(map(RGBposition, 0, 341, 0, 255), 0, 255) - constrain(map(RGBposition, 341, 682, 0,255), 0, 255);
blueValue = constrain(map(RGBposition, 341, 682, 0, 255), 0, 255) - constrain(map(RGBposition, 682, 1023, 0, 255), 0, 255);
analogWrite(RED_LED_PIN, redValue); analogWrite(GREEN_LED_PIN, greenValue); analogWrite(BLUE_LED_PIN, blueValue);
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
