I am trying to use analog potentiometer inputs and convert them to digital outputs. I read that the digital outputs are in-between the values 0 and 1023, so I wrote the following code:
//reads analog and converts to digital
//then it uses the digital output to turn on LEDs
int red = 7;
int green = 8;
int yellow = 9;
int val = 0;
void setup() {
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(yellow, OUTPUT);
Serial.begin(9600);
}
void loop() {
val = analogRead(A2);
Serial.println(val);
delay(1);
if (val >= 0 || val <= 255)
{
digitalWrite(red, HIGH);
}
else if(val >= 256 || val <= 511)
{
digitalWrite(yellow, HIGH);
}
else if(val >= 512 || val <=1023)
{
digitalWrite(green, HIGH);
}
}
There are no compiling errors.
The problem is only the red LED turns on and stays on. When I turn the potentiometer nothing else happens.
I am using an Elektor R4 board.
My TX LED is always on and my computer is connected to the board
I am also new to Arduino so please go easy on me. Am I doing something wrong, and is there an easier way to accomplish this?