Trouble mapping values from a 10k potentiometer

Im trying to map the values from the potent and use it to switch leds on and off, planning on eventually using this to display three different speeds for a stepper motor. Anyways, i can get my first two to work correctly. But i am not sure why the value is not being correctly mapped for my third (red) led to be activated. I have tried changing the values when mapped and in my if/ else if statements but to no avail, any help would really be appreciated.

int green =6;
int blue= 5;
int red= 2;
int potent=0;

void setup() {
  // put your setup code here, to run once:
  pinMode(green,OUTPUT);
  pinMode(blue,OUTPUT);
  pinMode(red,OUTPUT);
  pinMode(potent,INPUT);
}

void loop() {

int val=analogRead(potent);
val=map(val,0,1023,0,2);

if (0<val<1)
{
digitalWrite(green,HIGH);
digitalWrite(blue,LOW);
digitalWrite(red,LOW);
}

else if (1<val<2)
{
  digitalWrite(green,LOW);
digitalWrite(blue,HIGH);
digitalWrite(red,LOW);
}

else 
{
digitalWrite(green,LOW);
digitalWrite(blue,LOW);
digitalWrite(red,HIGH);
}

}
if (1<val<2)

It’ll compile, but may not do what you want.
The && operator is useful here

try this:

digitalWrite(green, 0==val);
digitalWrite(blue, 1==val);
digitalWrite(red, 2==val);

You ask too much of map.

It will return 2 only when input is 1023 or higher, I just ran a little program to see this.

If also your potentiometer is not ever getting all the way to the top of the reference voltage, map will never see 1023, never return 2.

int a, b;

void setup() {
  int ii;

  // put your setup code here, to run once:
  Serial.begin(9600);

  for (ii = 0; ii < 1050; ii += 17) {
    b = map(ii, 0, 1023, 0, 2);
    Serial.print(ii);
    Serial.print(" -> ");

    Serial.print(b);
    Serial.println();
  }
}


void loop() {
  // put your main code here, to run repeatedly:



}

– a7