Newbie question
deejayspinz
Posts: 6
Hi all,
I have a newb question about a project I am working on. It is about using momentary switches to trigger actions. I did some research and found the button command, but want to understand more about how to actually hook up the switch. Is it as simple as connecting the switch between 2 pins, setting 1 high and monitoring the second to see when it goes high and performing some action? Are there more efficient ways of doing this? Any other components that should be used (eg resistors?)
There are two things I would like to do:
1) to conserve battery power, I plan on having an LCD hooked up to display status info, but I dont want the LCD to be always on. So I was thinking that pressing the switch would turn the LCD on for say 5 seconds for example (and display stats), then turn back off.
2) I will be driving a number of IR LEDs as a Beacon using another part of the application. I have a robot that will 'dock' to the beacon and would like to turn off the PIN that drives the LED's when another switch is pressed (and remains pressed while the robot is docked).
Suggestions or code samples would be much appreciated. Thx!
I have a newb question about a project I am working on. It is about using momentary switches to trigger actions. I did some research and found the button command, but want to understand more about how to actually hook up the switch. Is it as simple as connecting the switch between 2 pins, setting 1 high and monitoring the second to see when it goes high and performing some action? Are there more efficient ways of doing this? Any other components that should be used (eg resistors?)
There are two things I would like to do:
1) to conserve battery power, I plan on having an LCD hooked up to display status info, but I dont want the LCD to be always on. So I was thinking that pressing the switch would turn the LCD on for say 5 seconds for example (and display stats), then turn back off.
2) I will be driving a number of IR LEDs as a Beacon using another part of the application. I have a robot that will 'dock' to the beacon and would like to turn off the PIN that drives the LED's when another switch is pressed (and remains pressed while the robot is docked).
Suggestions or code samples would be much appreciated. Thx!
Comments
http://www.parallax.com/Store/Books/AllBooks/tabid/763/CategoryID/41/List/0/SortField/0/catpageindex/2/Level/a/ProductID/139/Default.aspx
One of the early chapters talks about how to hookup a push button.
If I were doing this, I'd designate one pin on the BS as the button input..... tie the input to ground through a 10k resistor (so the input doesn't float) then hook your input to +5 through the switch:
The 10k resistor bleeds any noise to ground off the input pin. When you supply +5 to the input via the switch 0.5mA is bled though the resistor to ground. That lost current is TINY so the BS sees the HI state on the input pin.
Use your button instruction, set it to look for a HI state, set the debounce duration to 20ms and let it fly. If the results are flaky, you might need to increase the duration to as much as 100ms.
If you are using a 9V battery straight to the BS module (Not BOE board) then you should be powering the Vin pin (pin 24 on the 2px for example). The BS has an in-chip regulator and will allow you to use this regulator to power stuff..... so to pick 5V off the BS you'd connect your accessories to VDD (pin 21 of the 2px for example)
Be warned though, you can't pull a huge amount of power off the in-chip regulator and a short circuit could be very bad. You could fuse it, use a current limiting resistor or use a separate voltage regulator cheap from Radio Shack. Be careful.
Look in your manual, or pull the schematic off Parallax to determine which pin supplies 5V from your particular BS
P.S. I use the term "In-chip" loosely.... just to eliminate confusion
What is the best way to obtain a 5V source? Can I choose another pin and set it to hi at the beginning of the app and use it?
The PIN marked VDD is 5 volt How Ever DO NOT use it for any more than LED and very small servo not more than 100 milliamps MAX
Im supplying power via 9V battery.
This will not last long you need to use a wall wart or nicads to power your board
You want to set a Pin High and drive you LCD by it ?
The Stamp SX can Source/Sink : 30 mA / 30 mA current per I/O, witch means that you CAN NOT drive anything larger than that .. but that is not the best way to power anything anyway, the minimum you could do is connect this CONTROL I/O Pin (Let's call it POWER Pin) to and 1K Ohm resistor and to the BASE pin of an transistor, and let the weigh all for the transistor. Take a look at Nuts $ Volts #06. You can use the 5 Volt pin Vcc (Pin 21 on ALL DIP24 Basic Stamp) as an output, but it's not recommended just because the 5 Volt regulator of the BS module itself is considered an delicate power supply (due to size and funcionality).
Hope to Help
Amaral.