Tactile Switch Buttons
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_carter
- Posts: 29175
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Tactile Switch Buttons
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.
- Deck52
- Posts: 52
- Joined: Wed Aug 10, 2016 12:14 pm
Re: Tactile Switch Buttons
Wow, thanks. I'll send it tomorrow. Again, that's so much for the help. Learning tons. Cheers.
- Deck52
- Posts: 52
- Joined: Wed Aug 10, 2016 12:14 pm
Re: Tactile Switch Buttons
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 (263.22 KiB) Viewed 382 times
-
- w.jpg (351.5 KiB) Viewed 382 times
- adafruit_support_carter
- Posts: 29175
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Tactile Switch Buttons
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);
}
}
- Deck52
- Posts: 52
- Joined: Wed Aug 10, 2016 12:14 pm
Re: Tactile Switch Buttons
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.
- adafruit_support_carter
- Posts: 29175
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Tactile Switch Buttons
Sounds like maybe the Trinket didn't enter bootloader mode. Try uploading again.
- Deck52
- Posts: 52
- Joined: Wed Aug 10, 2016 12:14 pm
Re: Tactile Switch Buttons
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.
- adafruit_support_carter
- Posts: 29175
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Tactile Switch Buttons
Once the sketch is uploaded, press your tactile button you've soldered to #0 and GND. Not the reset button.when I hit the reset button
- Deck52
- Posts: 52
- Joined: Wed Aug 10, 2016 12:14 pm
Re: Tactile Switch Buttons
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.
- adafruit_support_carter
- Posts: 29175
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Tactile Switch Buttons
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?What I mean is that when I do hit the reset to upload the onboard red LED does not light up or flash anymore.
- Deck52
- Posts: 52
- Joined: Wed Aug 10, 2016 12:14 pm
Re: Tactile Switch Buttons
Just now. I uploaded the FastLED code and it runs fine. Code is uploading.
- Deck52
- Posts: 52
- Joined: Wed Aug 10, 2016 12:14 pm
Re: Tactile Switch Buttons
Does it matter on the button itself which lead the red and black is connected?
- adafruit_support_carter
- Posts: 29175
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Tactile Switch Buttons
Not on the button.Does it matter on the button itself which lead the red and black is connected?
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);
}
- Deck52
- Posts: 52
- Joined: Wed Aug 10, 2016 12:14 pm
Re: Tactile Switch Buttons
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?
- adafruit_support_carter
- Posts: 29175
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Tactile Switch Buttons
I'm not convinced it's uploading any code. If that blink sketch isn't working, then something is fundamentally wrong.
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.I uploaded the FastLED code and it runs fine.
Please be positive and constructive with your questions and comments.