So I'm working on a project that's really pushing the number of pins I need to use, and one of the ones I can cut is the current wiring to a switch if instead I can get a read off of this built in reset push button on the board itself. Took a quick look around the site itself, but didn't really find anything, is there a way to reference the state of that button in code, change it from resetting the board to a different use? Thanks to anyone who can help.
is there a way to reference the state of that button in code, change it from resetting the board to a different use? Thanks to anyone who can help.
I don't think so, pressing your reset switch cause your sketch to start from the beginning. You could cut a trace and rewire the switch to a digital input pin instead, but that doesn't save you a pin does it. Are you using all the pins including the analog input pins, because they can be used as digital pins also? If you want to try and post a schematic of your project perhaps someone here can come up with a cleaver means to free up a pin or two.
Lefty
Thanks for the help retrolefty. Hm, do I need to do anything special to use one of the analog pins as digital? Here's a recent version of my schematic, but instead of four resistor-LED pairs I have ten. Ten of those, one motor pin, one read pin, one switch pin and one additional LED pin is 14, or two over what I have usable (since 0 and 1 are the serial pins)
The circuit has four main systems, the switch/LED pair on the bottom (the LED is program controlled and just checks the switch state), the motor system in the middle, the LED control at the top, and the photo-transistor/infrared LED system.
To use the analog pins you just have to reference them as pins 14 to 19 to correspond to analog pins 0 to 5 in your pinMode() and digitalRead() and digitalWrite() commands.
One note if you are going to drive 10 or 11 leds directly from an Arduino output pins. The AVR mega chip as a maximum current rating of 200ma for all loads and internal requirements in total. So I would size your led resistors such that they draw only 10ma of less each. They will still be quite bright. Also you can free up that 10k ohm resistor used by the switch by just enabling the internal pull-up resistor for that pin.
Lefty
All 6 analog pins can be used as digital pins, too. They get number 14 through 19 on the Duemilanove, or you can use the aliases defined in 0021, A0, A1, A2, etc.
Alright, just a couple more questions. Will I be able to set the analog pins using digitalWrite = HIGH and LOW like the digital pins without any other baggage?
And is what you said about the LEDs going to be a problem if I'm only lighting one or two at a time?
Alright, just a couple more questions. Will I be able to set the analog pins using digitalWrite = HIGH and LOW like the digital pins without any other baggage?
No baggage to worry about.
And is what you said about the LEDs going to be a problem if I'm only lighting one or two at a time?
As long as total loads are under 200ma you are fine, so either make it impossible by resistor choice, or be sure your code won't ever try and turn them all or enough of them to draw more then that limit.
Lefty
Excellent, thanks. We were given this board for a college class, but once everything's done I think I'm going to have a lot of fun doing hobby work with it.
Excellent, thanks. We were given this board for a college class, but once everything's done I think I'm going to have a lot of fun doing hobby work with it.
Your welcome. And yes that Arduino can be a lot of fun for the low bucks and easy learning curve to get things working. I'm still amazed after 2 years of some of the cleaver projects people come up with.
Lefty