Somebody please help me. Almost a week I'm trying to solve my project. I'm not really sure if my codes are correct due to the procedure.
Please help me.. And I highly appreciate it...
Procedure:
Connect pins A0, A1 and A2 of the Arduino to the potentiometers. Also, connect pins 9-11 of the Arduino to pins R1, G1 and B1 respectively.
Create a program that detects two states (0 and 1, 0 means <=50% and 1 means >50%) for each three potentiometers and outputs the results to two RGB LEDs. Print the states of the potentiometers to Serial monitor. Follow the input-output relation in the table below:
POT1 POT2 POT3 RGB1 RGB2
0 0 0 RED BLUE
0 0 1 BLUE GREEN
0 1 0 GREEN RED
0 1 1 RED GREEN
1 0 0 BLUE RED
1 0 1 GREEN BLUE
1 1 0 BLUE BLUE
1 1 1 RED RED
Here the Materials:
1 x Arduino Uno board and USB cable
2 x RGB LEDs
1 x 150 Ω resistor
2 x 100Ω resistors and
3 x10k Ω potentiometer
1 x breadboard
Here's my code:
/*
Analog-To-Digital Conversion
*/
int redPin = 9; //Pin for the red RGB
int greenPin = 10; //Pin for the green RGB
int bluePin = 11; //Pin for the blue RGB
int Pin_Potentiometer1 = A0; //potentiometer for the LED
int Pin_Potentiometer2 = A1;
int Pin_Potentiometer3 = A2;
int readValue_red; //read value from the potentiometer which controls the LED
int readValue_green;
int readValue_blue;
int writeValue_red; //variable to send to the LED
int writeValue_green;
int writeValue_blue;
void setup() {
pinMode(Pin_Potentiometer1, INPUT); //potentiometer for the LED as input
pinMode(Pin_Potentiometer2, INPUT);
pinMode(Pin_Potentiometer3, INPUT);
pinMode(redPin,OUTPUT); //set pin for the LED as output
pinMode(bluePin,OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
readValue_red = analogRead(Pin_Potentiometer1); //Read voltage from potentiometer to control the LED
readValue_green = analogRead(Pin_Potentiometer2);
readValue_blue = analogRead(Pin_Potentiometer3);
writeValue_red = (255./1023.)*readValue_red;
writeValue_green = (255./1023.)*readValue_green;
writeValue_blue = (255./1023.)*readValue_blue;
analogWrite(redPin,writeValue_red); //write value to set the brightness of the LED
analogWrite(greenPin,writeValue_green);
analogWrite(bluePin,writeValue_blue);
}