Step 16Buttons
The buttons i bought were designed for PCB mounting, so whilst they fit onto the breadboard with a little encouragement, they need to have wires soldered on for the final board.
Somewhat strangely, buttons with four leads may have some interesting ways of making connections. Pins will connect diagonally, so an input at top left will give you an output bottom right. Pins on the same side will connect too. Pins opposite each other will not connect, however.
Wire one of the button connections into the PC3 pin (25). Use another wire to connecting the button to ground. This will be our shoot button.
The principle behind these switches is simple, with an internal pull up resistor enabled, the pin is set to logical 1 - there is an internal connection to VCC via a resistor. This connection also goes to the pin itself. When the switch is pushed, the electricity takes the path of least resistance and goes through the resistor and into ground - the microcontroller sees logical zero and says "something's happened".
If you're not going to use an external resistor connected to VCC on the pin, it is very important that you don't just connect up the button. You will leave the pin "floating", neither connected to VCC or Ground and that can cause lots of problems with false logic signals.
That's all you need to do to set the circuit up. The code "Remote Test" is fairly simple.
It is exactly the same as before, except we add some more functions and add the input, enabling pull-ups when we do so. When we set the Port as an input, using the DDR register, the PORT register then turns magically into a pull-up enabler. We write 1 into the required bit (for PC3) and that's done.
Next, we have a function for detecting button input, including debouncing (google for more info) the relevant pins to check it was a true button press.
It's worth pointing out that these codes are dreadfully inefficient for power consumption. It would be far better to sleep the processor when nothing is happening (i wanted to do this, but i didn't have the time to rewrite the code to compensate).
Upload the compiled program to the microcontroller and try out your remote!
Next we're going to add in the LCD screen.
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|

























































