Bio bi jako zahvalan na pomoci ukoliko netko ima rijesenje!
Spojio sam rgb ledicu koju trebam kontrolirati sa tri prekidaca i dva potenciometra..
Svaki prekidac pali odredjenu boju s time da na 1. i 2. boji mogu podesavati jacinu na 1. potenciometar, a
3. boja da se podešava na 2. potenciometar.
Negdje sam nešto promašio u programu jer mi se na 3. boji moze podesavati jacina ukoliko prekidac ostavim pritisnut..
Novi sam u programiranju pa molim za razumijevanje

Hvala!
Kod: Označite sve
int pot_pin1 = A0;
int pot_pin2 = A1;
int output;
int led_value1;
int led_value2;
const int GreenLED = 9;
const int BlueLED = 10;
const int RedLED = 11;
const int Led1 = 2;
const int Led2 = 8;
const int Led3 = 4;
// define Buttons code
const int GreenButton = 5;
const int BlueButton = 6;
const int RedButton = 7;
int pressed = 0;
void setup() {
// initialize the digital pin as an output.
pinMode(GreenLED,OUTPUT);
pinMode(BlueLED ,OUTPUT);
pinMode(RedLED ,OUTPUT);
pinMode(Led1, OUTPUT);
pinMode(Led2, OUTPUT);
pinMode(Led3, OUTPUT);
//input pins
pinMode(RedButton,INPUT_PULLUP);
pinMode(BlueButton,INPUT_PULLUP);
pinMode(GreenButton,INPUT_PULLUP);
}
void loop() {
//Reading from potentiometer
output = analogRead(pot_pin1);
led_value1 = map(output, 0, 1023, 0, 255);
output = analogRead(pot_pin2);
led_value2 = map(output, 0, 1023, 0, 255);
//Mapping the Values between 0 to 255 because we can give output
//from 0 -255 using the analogwrite funtion
delay(1);
boolean GreenIs = digitalRead(GreenButton);
boolean BlueIs = digitalRead(BlueButton);
boolean RedIs = digitalRead(RedButton);
delay(50);
if (pressed != 0){
analogWrite(pressed, led_value2);
analogWrite(pressed, led_value1);
}
if(GreenIs==false)
{
pressed = GreenLED;
analogWrite(GreenLED, led_value1); // turn the LED on (HIGH is the voltage level)
digitalWrite(Led1, 0);
digitalWrite(Led2, 1);
digitalWrite(Led3, 0);
analogWrite(BlueLED , 0); // turn the LED off by making the voltage LOW
analogWrite(RedLED , 0); // turn the LED off by making the voltage LOW
}
if(BlueIs==false)
{
pressed = BlueLED;
analogWrite(BlueLED , led_value1); // turn the LED on (HIGH is the voltage level)
digitalWrite(Led1, 1);
digitalWrite(Led2, 0);
digitalWrite(Led3, 0);
analogWrite(GreenLED , 0); // turn the LED off by making the voltage LOW
analogWrite(RedLED , 0); // turn the LED off by making the voltage LOW
}
if(RedIs==false)
{
pressed = RedLED;
analogWrite(RedLED , led_value2); // turn the LED on (HIGH is the voltage level)
digitalWrite(Led1, 0);
digitalWrite(Led2, 0);
digitalWrite(Led3, 1);
analogWrite(GreenLED , 0); // turn the LED off by making the voltage LOW
analogWrite(BlueLED , 0); // turn the LED off by making the voltage LOW
}
}