0

I can't get a simple button to work
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

I can't get a simple button to work

by bgambrell on Tue Sep 14, 2021 12:31 pm

I am apparently very bad at this.

I have a button, which is essentially a switch, and I've got it set up as a pull-down. I have some simple arduino code that reads the corresponding pin and if it is HIGH, it turns on the LED_BUILTIN.

I press the button. Nothing happens.

Code: Select all | TOGGLE FULL SIZE
int btn11Pin = 11;
int btn11State = 0;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(btn11Pin, INPUT);
}

void loop() {
  btn11State = digitalRead(btn11Pin);
  if (btn11State == HIGH) {
    digitalWrite(LED_BUILTIN, HIGH);
  } else {
    digitalWrite(LED_BUILTIN, LOW);
  }
 
}


I'm doing this on a Feather Bluefruit LE 32u4

Image
Last edited by bgambrell on Tue Sep 14, 2021 12:54 pm, edited 3 times in total.

bgambrell
 
Posts: 6
Joined: Tue Sep 14, 2021 12:07 pm

Re: I can't get a simple button to work

by adafruit_support_bill on Tue Sep 14, 2021 12:34 pm

If you post a photo of your circuit we can try to spot the problem.

adafruit_support_bill
 
Posts: 82099
Joined: Sat Feb 07, 2009 10:11 am

Re: I can't get a simple button to work

by bgambrell on Tue Sep 14, 2021 1:01 pm

edited

bgambrell
 
Posts: 6
Joined: Tue Sep 14, 2021 12:07 pm

Re: I can't get a simple button to work

by adafruit_support_bill on Tue Sep 14, 2021 1:04 pm

Try turning your button 90 degrees. The two pins you are connected to may be connected together internally.

adafruit_support_bill
 
Posts: 82099
Joined: Sat Feb 07, 2009 10:11 am

Re: I can't get a simple button to work

by bgambrell on Tue Sep 14, 2021 1:06 pm

Not the issue. I can wire the pin directly to the logic power and it still does nothing.

Is there a different way to reference the pins?

bgambrell
 
Posts: 6
Joined: Tue Sep 14, 2021 12:07 pm

Re: I can't get a simple button to work

by adafruit_support_bill on Tue Sep 14, 2021 3:05 pm

What do you have connected to pin 13?

adafruit_support_bill
 
Posts: 82099
Joined: Sat Feb 07, 2009 10:11 am

Re: I can't get a simple button to work

by bgambrell on Tue Sep 14, 2021 5:15 pm

It was grounded but I removed it from ground and now the button is sort of working. The LED is very dim when I press the button. Not as bright as it should be.

bgambrell
 
Posts: 6
Joined: Tue Sep 14, 2021 12:07 pm

Re: I can't get a simple button to work

by bgambrell on Tue Sep 14, 2021 5:17 pm

I decided off-hand to re-upload my sketch. And now it works! I am happy because it works. I am sad because I do not understand what was happening.

bgambrell
 
Posts: 6
Joined: Tue Sep 14, 2021 12:07 pm

Re: I can't get a simple button to work

by adafruit_support_bill on Tue Sep 14, 2021 6:43 pm

Pin 13 drives the on-board LED. With it shorted to ground, it cannot not go HIGH to turn on the on-board LED. (That is also a good way to burn-out the output drivers for the pin.)

adafruit_support_bill
 
Posts: 82099
Joined: Sat Feb 07, 2009 10:11 am

Re: I can't get a simple button to work

by bgambrell on Thu Sep 16, 2021 10:51 am

Thank you!

bgambrell
 
Posts: 6
Joined: Tue Sep 14, 2021 12:07 pm

Please be positive and constructive with your questions and comments.