so i am a bit of a newbie with Arduino,
i wrote this code for a potmeter with a RGB.
my code works fine if i cancel out the;
if (potValue > 340 < 680)digitalWrite(GREEN,HIGH);
i can turn my pot and it will give me red and blue and the colors go off if i go into the potValue < 340 < 680 range.
but if i turn on the green high, it goes all green no matter how i turn it...
could somebody take a look at my code and say what's wrong?
ps i am pretty sure i set my Arduino op right.
int potPin = A0;
int potValue = 0;
const byte RED = 10;
const byte GREEN = 11;
const byte BLUE = 12;
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
if (potValue < 340) digitalWrite(RED, HIGH);
if (potValue < 340) digitalWrite(BLUE,LOW) ;
if (potValue < 340) digitalWrite(GREEN,LOW);
if (potValue > 680) digitalWrite(BLUE,HIGH);
if (potValue > 680) digitalWrite(RED, LOW) ;
if (potValue > 680)digitalWrite(GREEN,LOW);
if (potValue > 340 < 680)digitalWrite(GREEN,HIGH); //this is where it goes wrong if i cancel this one out it works like it should, but if i put it in it goes all green, no matter how i turn th pot
if (potValue > 340 < 680) digitalWrite(RED,LOW);
if (potValue > 340 < 680)digitalWrite(BLUE,LOW);
This is a very common question.
The expression evaluates left to right.
"Is potValue > 340?" - the answer is true (1) or false (0)
"is 1 or 0 < 680" Yes - always.
ohw i'm sorry i wired the pot up to take values and if that value is lower than 340 i want the RGB to shine red, between 340 and 680 green and between 680 and higher blue.
also quick add, if i cancel the green out, the blue and red show but very weak.