I have a weird issue.
I have four buttons hooked up on A0.
(example https://www.the-diy-life.com/multiple-push-buttons-on-one-arduino-input/).
It only works with 1 IF. With other values the led is very dim (but does react).
The serial monitor does recoqnize the right values and I tried both polarities (button to positive and to negative). Serial monitor keeps reading the right values but only 1 IF gives a bright LED.
So for some reason when I enable more than one IF, I get no 5V.
I tried multiple digital pins as well.
Code below (I have been testing so not beautiful coding)
WTF am I doing wrong? As you can see I disabled all but one IF, now I get a LED bright. If I enable another it goes wild. Why?
//Michael Klements
//The DIY Life
//17 May 2019
int ledPin = 10; // choose the pin for the LED
int buttonValue = 0;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(A0, INPUT);
}
void loop()
{
Serial.println(buttonValue);
buttonValue = analogRead(A0); //Read in the button value
//if (buttonValue>=1009 && buttonValue<=1020) //Switch the LED on if button is pressed
// digitalWrite(ledPin, HIGH);
if (buttonValue>=80 && buttonValue<=100)
digitalWrite(ledPin, HIGH);
//if (buttonValue>=984 && buttonValue<=997)
// digitalWrite(ledPin, HIGH);
//if (buttonValue>=953 && buttonValue<=982)
// digitalWrite(ledPin, HIGH);
//if (buttonValue>=910 && buttonValue<=951)
// digitalWrite(ledPin, HIGH);
else
digitalWrite(ledPin, LOW); //Switch the LED off if button is not pressed
//delay(2000);
}