Tactile Switch Buttons

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
adafruit_support_carter
 
Posts: 29175
Joined: Tue Nov 29, 2016 2:45 pm

Re: Tactile Switch Buttons

Post by adafruit_support_carter »

Wire the button between #0 and GND on the Trinket. Post a photo once you've done that solder work showing this. If it looks OK I will give you some code to show how you can read the button.

User avatar
Deck52
 
Posts: 52
Joined: Wed Aug 10, 2016 12:14 pm

Re: Tactile Switch Buttons

Post by Deck52 »

Wow, thanks. I'll send it tomorrow. Again, that's so much for the help. Learning tons. Cheers.

User avatar
Deck52
 
Posts: 52
Joined: Wed Aug 10, 2016 12:14 pm

Re: Tactile Switch Buttons

Post by Deck52 »

I wired it like you said and also cleaned up all my connections. So now I need the button to turn the LEDs on in that FastLED code when the button is UP and off when it's DOWN. Thanks again for all your help.
Attachments
q.jpg
q.jpg (263.22 KiB) Viewed 382 times
w.jpg
w.jpg (351.5 KiB) Viewed 382 times

User avatar
adafruit_support_carter
 
Posts: 29175
Joined: Tue Nov 29, 2016 2:45 pm

Re: Tactile Switch Buttons

Post by adafruit_support_carter »

Looks good. Here's the code to try. At this point it does nothing with the NeoPixels. It will simply turn on/off the little red LED on the Trinket next to the USB connector.

Code: Select all

#define BUTTON_PIN  0     // the pin to which the button is attached
#define LED_PIN     1     // the onboard red LED pin

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);  // use of PULLUP is important
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  if (digitalRead(BUTTON_PIN) == LOW) {
    // button is pressed
    digitalWrite(LED_PIN, HIGH);
  } else {
    // button is NOT pressed
    digitalWrite(LED_PIN, LOW);
  }
}

User avatar
Deck52
 
Posts: 52
Joined: Wed Aug 10, 2016 12:14 pm

Re: Tactile Switch Buttons

Post by Deck52 »

Didn't work. However, I noticed that when I hit the reset button the trinket LED didn't light up, but it upload the code.

User avatar
adafruit_support_carter
 
Posts: 29175
Joined: Tue Nov 29, 2016 2:45 pm

Re: Tactile Switch Buttons

Post by adafruit_support_carter »

Sounds like maybe the Trinket didn't enter bootloader mode. Try uploading again.

User avatar
Deck52
 
Posts: 52
Joined: Wed Aug 10, 2016 12:14 pm

Re: Tactile Switch Buttons

Post by Deck52 »

Weird. The code is definitely loading because I uploaded the FASTLED code and the Neo lights up. But the LED on the trinket does not light when I use your code or when I hit the reset button. Can we try to have the switch work the NEO since we know that's lighting up? Thanks.

User avatar
adafruit_support_carter
 
Posts: 29175
Joined: Tue Nov 29, 2016 2:45 pm

Re: Tactile Switch Buttons

Post by adafruit_support_carter »

when I hit the reset button
Once the sketch is uploaded, press your tactile button you've soldered to #0 and GND. Not the reset button.

User avatar
Deck52
 
Posts: 52
Joined: Wed Aug 10, 2016 12:14 pm

Re: Tactile Switch Buttons

Post by Deck52 »

Yep, that's what I'm doing. What I mean is that when I do hit the reset to upload the onboard red LED does not light up or flash anymore.

User avatar
adafruit_support_carter
 
Posts: 29175
Joined: Tue Nov 29, 2016 2:45 pm

Re: Tactile Switch Buttons

Post by adafruit_support_carter »

What I mean is that when I do hit the reset to upload the onboard red LED does not light up or flash anymore.
This sounds like the Trinket is not entering bootloader mode. When was the last time you were able to successfully upload a sketch to it?

User avatar
Deck52
 
Posts: 52
Joined: Wed Aug 10, 2016 12:14 pm

Re: Tactile Switch Buttons

Post by Deck52 »

Just now. I uploaded the FastLED code and it runs fine. Code is uploading.

User avatar
Deck52
 
Posts: 52
Joined: Wed Aug 10, 2016 12:14 pm

Re: Tactile Switch Buttons

Post by Deck52 »

Does it matter on the button itself which lead the red and black is connected?

User avatar
adafruit_support_carter
 
Posts: 29175
Joined: Tue Nov 29, 2016 2:45 pm

Re: Tactile Switch Buttons

Post by adafruit_support_carter »

Does it matter on the button itself which lead the red and black is connected?
Not on the button.

Does this blink sketch work? Does it blink the red LED constantly?

Code: Select all

#define LED_PIN     1     // the onboard red LED pin

void setup() {
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_PIN, HIGH);
  delay(100);
  digitalWrite(LED_PIN, LOW);
  delay(200);  
}

User avatar
Deck52
 
Posts: 52
Joined: Wed Aug 10, 2016 12:14 pm

Re: Tactile Switch Buttons

Post by Deck52 »

No. It was working before I wired this new configuration up and it is uploading code. Since it is uploading code can we just try to turn the neo on and off?

User avatar
adafruit_support_carter
 
Posts: 29175
Joined: Tue Nov 29, 2016 2:45 pm

Re: Tactile Switch Buttons

Post by adafruit_support_carter »

I'm not convinced it's uploading any code. If that blink sketch isn't working, then something is fundamentally wrong.
I uploaded the FastLED code and it runs fine.
So you think this is uploading and running OK? Change something in that code, like a color or something, and see if you can re-upload and see the changes.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”