0% found this document useful (0 votes)
2 views1 page

prac9

The document contains an Arduino code that controls an RGB LED based on the input from a potentiometer. It defines pins for red, blue, and green colors, and uses a function to set the LED color based on the potentiometer's value. The loop reads the potentiometer value, maps it to a mode, and sets the RGB LED accordingly.

Uploaded by

trishak2305
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)
2 views1 page

prac9

The document contains an Arduino code that controls an RGB LED based on the input from a potentiometer. It defines pins for red, blue, and green colors, and uses a function to set the LED color based on the potentiometer's value. The loop reads the potentiometer value, maps it to a mode, and sets the RGB LED accordingly.

Uploaded by

trishak2305
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/ 1

#define RGB_RED_PIN 11

#define RGB_BLUE_PIN 9
#define RGB_GREEN_PIN 10
#define POTENTIOMETER_PIN A0

void digitalWriteRGB(byte red, byte blue, byte green)


{
digitalWrite(RGB_RED_PIN, red);
digitalWrite(RGB_BLUE_PIN, blue);
digitalWrite(RGB_GREEN_PIN, green);
}

void setup()
{
pinMode(RGB_RED_PIN, OUTPUT);
pinMode(RGB_BLUE_PIN, OUTPUT);
pinMode(RGB_GREEN_PIN, OUTPUT);
}

void loop()
{
int potentiometerValue = analogRead(POTENTIOMETER_PIN);
int mode = map(potentiometerValue, 0, 1023, 0, 6);

switch (mode) {
case 0:
digitalWriteRGB(HIGH, LOW, LOW);
break;
case 1:
digitalWriteRGB(LOW, HIGH, LOW);
break;
case 2:
digitalWriteRGB(LOW, LOW, HIGH);
break;
case 3:
digitalWriteRGB(HIGH, HIGH, LOW);
break;
case 4:
digitalWriteRGB(HIGH, LOW, HIGH);
break;
case 5:
digitalWriteRGB(LOW, HIGH, HIGH);
break;
case 6:
digitalWriteRGB(HIGH, HIGH, HIGH);
break;
default:
digitalWriteRGB(LOW, LOW, LOW);
break;
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy