Video Demo: Pinary Counter Demo
Description: A binary counter using buttons and LED's, written in Python for the RaspberryPi. Written for my Final CS50 Project.
Home Page: Pinary Counter
Author: Luke Melaia
Pinary Counter is an 8-bit binary counter - a program which counts up or down from 0 to 255 in increments of 1, using 8 bits to store and display the count. The counter will loop back and start counting again from 0 when counting up past 255, looping back to 255 instead when counting down below 0.
For user interaction, using Raspberry Pi and the GPIOZero library, Pinary Counter uses: 8 LED's to display the 8 bit counter output to the user, and 2 Buttons for the user to increment and decrement the counter. The Buttons can be held to increment and decrement the counter quicker. An extra (optional) indicator LED can also be connected, which is lit when the Pinary Counter program is running, and turned off when it stops.
Pinary counter works by first creating a normal binary counter, and then bridges the gap from software logic to hardware, using a Raspberry Pi, and its GPIO pins, to enable external button control, and LED's to display the binary output.
First, connect up 9 LED's and 2 Buttons to a bread-board, with appropriate resistors in place, and connect them up to the GPIO pins of a Raspberry Pi, using the provided pinout below.
Second, ensure Pinary Counter project files are available on the Raspberry Pi, and all included libraries are installed and available. Then run python pinary_counter.py from the project directory. After short delay, the indicator LED will light up, and the counter is ready to be used.
- pinary_counter.py Contains the logic to create binary counters, and use them to count up/down in binary, as well the logic to control the binary counter using buttons, and see the output with LED's using RaspberryPi.
- test_pinary_counter.py Tests that the code written in pinary_counter.py functions correctly.
- GPIOZero - to interface with the Raspberry Pi's GPIO pins.
- atexit - to register shutdown hooks.
== L1 L2 L3 L4 L5 L6 == L7 L8 -- 3V -- -- -- == -- -- -- 3V Pin 1
Pin 40 -- -- -- == LI == BI BD -- -- == -- -- == -- -- -- == 5V 5V
| Component | ID | Pin Number | GPIO Pin Number |
|---|---|---|---|
| Increment Button | BI | 28 | 1 |
| Decrement Button | BD | 26 | 7 |
| Indicator LED | LI | 32 | 12 |
| Bit-128 LED | L1 | 37 | 26 |
| Bit-64 LED | L2 | 35 | 19 |
| Bit-32 LED | L3 | 33 | 13 |
| Bit-16 LED | L4 | 31 | 6 |
| Bit-8 LED | L5 | 29 | 5 |
| Bit-4 LED | L6 | 27 | 0 |
| Bit-2 LED | L7 | 23 | 11 |
| Bit-1 LED | L8 | 21 | 9 |
| 3 Volts | 3V | ||
| 5 Volts | 5V | ||
| Ground | == | ||
| Not Used | -- |


