Why is variable "r" always one, even if i ground pin 3?

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
int linpin = A1;
int rotpin = A0;
int selrot = 2;
int sellin = 3;
int spd;
float pot;
void setup() {
// put your setup code here, to run once:
lcd.init();
lcd.backlight();
pinMode(linpin, INPUT);
pinMode(rotpin, INPUT);
pinMode(selrot, INPUT);
pinMode(sellin, INPUT);
}

void loop() {
int r = digitalRead(3);
while (r= 1)
{

pot = analogRead(A1);
spd = map(pot,0,1023,0,100);
lcd.setCursor(0,0);
lcd.print("Linear");
lcd.setCursor(0,1);
lcd.print(spd);
lcd.setCursor(15,1);
lcd.print(r);
r = digitalRead(3);
}
while (r = 0){

pot = analogRead(A0);
spd = map(pot,0,1023,0,100);
lcd.setCursor(0,0);
lcd.print("Rotary");
lcd.setCursor(0,1);
lcd.print(spd);
lcd.setCursor(15,1);
lcd.print(r);
r = digitalRead(3);
}
}

Any help is deeply appreciated

You missed the code tags.
How is your switch wired ?
Why have you named the pins, but not used the names ?

Easy to fix with the right information.

Try:

pinMode(sellin, INPUT_PULLUP);

BTW

while (r= 1) is not the same as while (r==1) :wink:

1 Like

Please use CTRL-T to format your code, then use code tags when posting.

There's your problem.

The switch is wired so
it has three pins, one is 5 volts, one is input, one is ground

| | |
V I G

What code tags?
and i did use the names, until i started debugging, when it became easier to use the pins

If you post your code as described in How to get the best out of this forum, more forum members will read it.

Thank you, i wasnt comparing