0% found this document useful (0 votes)
33 views2 pages

Arduino - RGB

The document defines pin assignments for red, green, and blue LEDs and a button. It initializes the pin modes in setup() and uses the button to cycle through different color combinations in loop(), changing the LED brightness levels to produce different colors. Pushing the button increments a color variable to change the output each time.

Uploaded by

xMash 2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views2 pages

Arduino - RGB

The document defines pin assignments for red, green, and blue LEDs and a button. It initializes the pin modes in setup() and uses the button to cycle through different color combinations in loop(), changing the LED brightness levels to produce different colors. Pushing the button increments a color variable to change the output each time.

Uploaded by

xMash 2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//RGB

#define RED 6
#define GREEN 5
#define BLUE 3
//BUTON
#define BUTTON 2

//Culoarea
int color = 1;

void setup()
{
pinMode(RED, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BUTTON, INPUT_PULLUP);
}

void loop()
{
if(digitalRead(BUTTON) == LOW){
++color;
delay(400);
}
if(color == 1){
analogWrite(RED, 255);
analogWrite(GREEN, 0);
analogWrite(BLUE, 0);
}

if(color == 2){
analogWrite(RED, 255);
analogWrite(GREEN, 69);
analogWrite(BLUE, 0);
}

if(color == 3){
analogWrite(RED, 255);
analogWrite(GREEN, 255);
analogWrite(BLUE, 0);
}

if(color == 4){
analogWrite(RED, 0);
analogWrite(GREEN, 255);
analogWrite(BLUE, 0);
}

if(color == 5){
analogWrite(RED, 0);
analogWrite(GREEN, 0);
analogWrite(BLUE, 255);
}

if(color == 6){
analogWrite(RED, 0);
analogWrite(GREEN, 0);
analogWrite(BLUE, 128);
}
if(color == 7){
analogWrite(RED, 255);
analogWrite(GREEN, 0);
analogWrite(BLUE, 255);
}

if(color == 8){
analogWrite(RED, 0);
analogWrite(GREEN, 0);
analogWrite(BLUE, 0);
color = 0;
}

You might also like