![Photo](http://forums.netduino.com/uploads/av-2.png?_r=0)
Reversing the pushbutton state -- feedback?
#1
Posted 09 August 2010 - 03:49 PM
#2
Posted 09 August 2010 - 04:11 PM
![:)](http://forums.netduino.com/public/style_emoticons/default/smile.png)
#3
Posted 09 August 2010 - 04:12 PM
By default, the Netduino's pushbutton (SW1) acts as a reset button.
But if you create an InputPort (or InterruptPort) using Pins.ONBOARD_SW1, the pushbutton becomes a GPIO input--and can be read from your C# code.
We posted two videos showing how to use this feature:
One of our viewers has commented that having the pushbutton return FALSE when pushed and TRUE when _not_ pushed seems backwards. This is because the GPIO is tied high (3.3V) by default and pushing the button drives it to ground (0V).
Is anyone opposed to reversing this logic in firmware (i.e. pushing the button would return TRUE, releasing the button would return FALSE)?
I'm not normally a big fan of making changes that could alter code functionality, but I tend to agree that the logic would be simpler if reversed.
Thanks for the feedback, everyone (and in this paricular case, YouTube user smjjasdfa).
Chris
I'm up for reversing it. When the button is pushed, it is usually said that it's state is TRUE.
#4
Posted 09 August 2010 - 05:03 PM
#5
Posted 09 August 2010 - 06:07 PM
Shouldn't the SW1 button act like all the other GPIO's?
If you start out by using the SW1 for input, but later on decides to use another pin for the button, it wouldn't be good to require further code changes.
The way the button is wired (Pull-Up scenario) is pretty common, and having all GPIO's "inverted" wouldn't be fun is you ask me.
I'd say that a LOW signal on a pin should be FALSE, and a HIGH signal should be TRUE - Including the SW1 input.
Just my 5 cents...
/Thomas
You can make a good case for either option. I think the real problem is that a Port is fairly generic, while connecting a switch to an input port is a specific use case.
A couple of suggestions:
1. Define a new switch-specific enumeration, so that ON corresponds to boolean false, and OFF corresponds to boolean true.
2. Derive a Switch class from the InputPort class, and give the Switch class semantics that make sense for a switch (reading the state as being On/Off, Open/Closed, etc.).
Option 1 is probably simpler, while option 2 may be a "next version" type of thing.
Thanks,
-David
~ David ~
#6
Posted 09 August 2010 - 06:49 PM
#7
Posted 09 August 2010 - 07:28 PM
![:)](http://forums.netduino.com/public/style_emoticons/default/smile.png)
#8
Posted 09 August 2010 - 07:29 PM
Chris, I'm really liking this open dialog you have with your user community. Keep up the good work, and keep the tutorial videos coming!
Thank you! And we will!
#9
Posted 09 August 2010 - 07:45 PM
Thank you! And we will!
I don't think it's a good idea to reverse it. It makes more sense to keep it as it is now. If you look at it from the electronic perspective, by default, the button is tied to +5v/+3.3v so that it won't float. When the button gets pushed, electronically, it now makes the connection to ground and therefore it is false.
It will be very confusing to people coming from an electronic background if this gets changed. Perhaps people coming from a software background should get their hands wet in electronic to understand at least the basic stuff. Just my 2 cents.
By the way, I'm a certified electronic technician and a graduate in Computer Science.
Thanks!
#10
Posted 10 August 2010 - 04:47 AM
#11
Posted 10 August 2010 - 05:44 AM
Even though it would be easier to say change it for software people, I feel that leaving it "as is" Is the proper thing to do. I want to learn the the electronics/hardware side of what I'm coding against the right way- it's as if I'm taking a trip from my home country of software-landia to hardware-ica and I should learn the customs to make the most of my journey.
I totally agree with RedHermit. By changing this, it's like we are lying to ourself of what's really going on behind the scene. So I suggest that we leave it as is.
#12
Posted 10 August 2010 - 08:48 PM
#13
Posted 11 August 2010 - 02:43 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users