0% found this document useful (0 votes)
18 views

Arduino RGB

This Arduino code defines pins for red, green, and blue LEDs as well as analog input pins connected to potentiometers to control the brightness of each color. It sets the LED pins as outputs and potentiometer pins as inputs. The main loop function reads the potentiometer values, scales them to PWM brightness values between 0-255, and writes the brightness values to the corresponding LED pins to control the color mix.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Arduino RGB

This Arduino code defines pins for red, green, and blue LEDs as well as analog input pins connected to potentiometers to control the brightness of each color. It sets the LED pins as outputs and potentiometer pins as inputs. The main loop function reads the potentiometer values, scales them to PWM brightness values between 0-255, and writes the brightness values to the corresponding LED pins to control the color mix.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Arduino - RGB

Arduino - RGB
int red = 10, green = 9, blue = 11;
int potred=A0, potgreen = A1, potblue = A2;
int readred, readgreen, readblue;
int writered, writegreen, writeblue;

void setup() {
// put your setup code here, to run once:
pinMode(potred, INPUT);
pinMode(potgreen, INPUT);
pinMode(potblue, INPUT);

pinMode(potred, OUTPUT);
pinMode(potgreen, OUTPUT);
pinMode(potblue, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
readred = analogRead(potred);
readgreen = analogRead(potgreen);
readblue = analogRead(potblue);

writered = (255./1023.)*readred;
writegreen = (255./1023.)*readgreen;
writeblue = (255./1023.)*readblue;

analogWrite(red,writered);
analogWrite(green,writegreen);
analogWrite(blue,writeblue);
}

You might also like