Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
41 views7 pages

Arduino RGB LED Control

This document contains the source code for an Arduino program that controls the color of an RGB LED based on the value read from three potentiometers connected to analog pins A0, A1, and A2. The program continuously reads the potentiometer values and sets the LED color accordingly, cycling through each potentiometer until the reading reaches the minimum or maximum value.

Uploaded by

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

Arduino RGB LED Control

This document contains the source code for an Arduino program that controls the color of an RGB LED based on the value read from three potentiometers connected to analog pins A0, A1, and A2. The program continuously reads the potentiometer values and sets the LED color accordingly, cycling through each potentiometer until the reading reaches the minimum or maximum value.

Uploaded by

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

Nama : ARBI INDRAWAN

Nim : 41416120064
Tugas : Jawaban Forum 6 Robotika
TUGAS FORUM 6

1. Berikut ini merupakan komponen-komponen yang digunakan.

2. Gambar Skema Rangkaian


3. Proses Pengujian Rangkaian dan Program

4. Source Code Arduino


#define pinR 9
#define pinG 10
#define pinB 11
#define pinPot A0

void setup() {
pinMode( pinR, OUTPUT);
pinMode( pinG, OUTPUT);
pinMode( pinB, OUTPUT);

pinMode( pinPot, INPUT);


}

void loop() {
int sensorVal = analogRead(pinPot);

if( 0 <= sensorVal && sensorVal <= 341 )


{
byte red = map(sensorVal,0,341,0,255);
analogWrite( pinR,red);
analogWrite( pinG,0);
analogWrite( pinB,0);
}
else if ( 342 <= sensorVal && sensorVal <= 682 )
{
byte green = map(sensorVal, 342,682,0,255);
analogWrite( pinR,255);
analogWrite( pinG,green);
analogWrite( pinB,0);
}
else
{
byte blue = map(sensorVal,683,1023,0,255);
analogWrite( pinR,255);
analogWrite( pinG,255);
analogWrite( pinB,blue);
}
}
Nama : ARBI INDRAWAN
Nim : 41416120064
Tugas : Jawaban Forum 6 Robotika
TUGAS FORUM 6 Modifikasi

1. Berikut ini merupakan komponen-komponen yang digunakan.

2. Gambar Skema Rangkaian


3. Proses Pengujian Rangkaian dan Program

4. Source Code Arduino


#define pinR 9
#define pinG 10
#define pinB 11

#define pinPot1 A0
#define pinPot2 A1
#define pinPot3 A2

#define pinState1 3
#define pinState2 4
#define pinState3 7

int Array_State[3]= {pinState1, pinState2, pinState3};


int sensorValue;
bool Flag= false;

void setup() {
Serial.begin(9600);
pinMode( pinR, OUTPUT);
pinMode( pinG, OUTPUT);
pinMode( pinB, OUTPUT);
pinMode( pinPot1, INPUT);
pinMode( pinPot2, INPUT);
pinMode( pinPot3, INPUT);
pinMode( pinState1, OUTPUT);
pinMode( pinState2, OUTPUT);
pinMode( pinState3, OUTPUT);
}

void loop()
{
while(analogRead(A0) > 0 ) {
Potensio(0,0);
digitalWrite(pinState2, HIGH);
digitalWrite(pinState3, HIGH);
Serial.print("A0 =");
delay(100);
if(sensorValue >=1000 || sensorValue==0)
{
Flag=false;
break;
}
}
while(analogRead(A1) > 0) {
Potensio(1,1);
digitalWrite(pinState1, HIGH);
digitalWrite(pinState3, HIGH);
Serial.print("A1 =");
delay(100);
if(sensorValue >=1000 || sensorValue==0) {
Flag=false;
break;
}
}
while(analogRead(A2) > 0) {
Potensio(2,2);
digitalWrite(pinState1, HIGH);
digitalWrite(pinState2, HIGH);
Serial.print("A2 =");
delay(100);
if(sensorValue >=1000 || sensorValue==0) {
Flag=false;
break;
}
}
}
void Potensio(int a, int state)
{
sensorValue = analogRead(a);
digitalWrite(Array_State[state], LOW);
Flag=true;
Serial.println(sensorValue);
Pola();
}

/////////////////////////////////////
void Pola()
{
if( 0 <= sensorValue && sensorValue <= 341 )
{
byte red = map(sensorValue,0,341,0,255);
analogWrite( pinR,red);
analogWrite( pinG,0);
analogWrite( pinB,0);
}
else if ( 342 <= sensorValue && sensorValue <= 682 )
{
byte green = map(sensorValue, 342,682,0,255);
analogWrite( pinR,255);
analogWrite( pinG,green);
analogWrite( pinB,0);
}
else
{
byte blue = map(sensorValue,683,1023,0,255);
analogWrite( pinR,255);
analogWrite( pinG,255);
analogWrite( pinB,blue);
}
}

You might also like