I am doing a project with edge lit acrylic designs with my junior exploring computer science students at Boston's Madison Park Technical Vocational High School. I usually use a regular trinket for this project, but this time, I decided to try a Trinket MO.
Well, I got the blinkie sketch on the Trinket MO working and I got a simple one color neopixel strip code to upload just fine.
But now I am stuck on adding the rocker switch code.
The Adafruit tutorial on using Arduino says I have to use pinMode (RockerSwitchPIN, INPUT_PULLUP) in the void setup (). So I did that.
I used Switch = digitalRead(RockerSwitchPIN) & an if statement with if (Switch = 1) {}
This doesn't work. I checked that the switch is on pin 5 and grounded just fine.
What am I doing wrong? I've attached a copy of the code I am using.
Thank you for any help you can give me. . .
Trinket MO: How to code rocker switch in Arduino
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- zackboston
- Posts: 129
- Joined: Mon Feb 25, 2013 12:47 pm
Trinket MO: How to code rocker switch in Arduino
- Attachments
-
- RockerSwitchCode.png (233.11 KiB) Viewed 1622 times
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Trinket MO: How to code rocker switch in Arduino
With the Switch pin mode set to INPUT_PULLUP, the input will be pulled HIGH (1) by default when the switch is open.
The rocker switch should be connected between your Switch pin and GND. When you close the switch, the pin will be pulled LOW (0). So you should change your code to:
Also note that I used '==', not '='. '=' is the assignment operator. '==' is the equality operator.
The rocker switch should be connected between your Switch pin and GND. When you close the switch, the pin will be pulled LOW (0). So you should change your code to:
Code: Select all
if (Switch == 0)
- zackboston
- Posts: 129
- Joined: Mon Feb 25, 2013 12:47 pm
Re: Trinket MO: How to code rocker switch in Arduino
Thank you. . . I will try when I get to school!!!
I did try the == but I think I might have mis-typed the rocker switch pin number on that iteration of trying the code! . . .
I did try the == but I think I might have mis-typed the rocker switch pin number on that iteration of trying the code! . . .
- zackboston
- Posts: 129
- Joined: Mon Feb 25, 2013 12:47 pm
Re: Trinket MO: How to code rocker switch in Arduino
OK. It still doesn't work.
I tried using two if statements Switch == 0 and Switch ==1 to see what is going on.
I attached code. It must be some stupid simple bug. . .
I tried using two if statements Switch == 0 and Switch ==1 to see what is going on.
I attached code. It must be some stupid simple bug. . .
- Attachments
-
- Screen Shot 2022-02-18 at 6.06.28 AM.png (280.01 KiB) Viewed 1620 times
- Franklin97355
- Posts: 23911
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Trinket MO: How to code rocker switch in Arduino
You might get more info if you print the value of Switch before each if statement to see if it is what you expect.
- zackboston
- Posts: 129
- Joined: Mon Feb 25, 2013 12:47 pm
Re: Trinket MO: How to code rocker switch in Arduino
Oh Franklin, thank YOU!
Putting in a Serial.print was SOOOO HELPFUL and solved the problem!!!!
Success!!! I don't know why the Trinket MO confounded me so much. . . I've been using regular trinkets for years!!!
Putting in a Serial.print was SOOOO HELPFUL and solved the problem!!!!
Success!!! I don't know why the Trinket MO confounded me so much. . . I've been using regular trinkets for years!!!
Please be positive and constructive with your questions and comments.