Loading...

8-bit LED Binary Counter

View: 52    Dowload: 0   Comment: 0   Post by: admin   Category: Mobile applications   Fields: Other

Download  8-bit-led-binary-counter.zip (182.95 KB)

You need to Sign In to download the file 8-bit-led-binary-counter.zip
If you do not have an account then Sign up for free here

Introduction

This article offers a simple implementation of the binary counter powered by Raspberry PI3 and 8 LEDs. It is very similar to what was done before for Arduino board in the previous article Connecting an Arduino to a Breadboard to Light Up LEDs. In this project, we will be using Python to program the board.

For this project, we will need a Raspberry PI kit (I'm using one of these CanaKits), a breadboard, 8 LEDs, 8 220 Ohm resistors (can be different, e.g., 330, etc.) and 9 male-to-female jumper wires. If you decide not to remote to Raspberry, then you will also need a monitor with HDMI cable, mouse and keyboard.

Setting Up Work Environment

I'm using a default installation of Raspberry PI 3 which comes with Raspbian OS and Python pre-installed. Make sure you have the latest GPIO module installed as the code uses it to write to GPIO pins.

$ sudo apt-get update
$ sudo apt-get install python-rpi.gpio python3-rpi.gpio

I enabled Wi-Fi on my Raspberry and also configured Secure Shell (SSH), so I can remote to it from my Windows machine using Putty. This way, we won't need a monitor, mouse, keyboard and Ethernet cable to communicate with the device. The only cable that we need is a power cord.

After installing Samba on Raspberry, we can access working files from Windows machine and edit them in our favorite text editors. Alternatively, we still can use nano editor in terminal window which comes with the distribution.

Connecting Wires

We will need 8 wires to connect GPIO pins to corresponding LEDs via their individual resistors (plus 1 wire for the ground). Here, I decided to use pin 33 for bit 0, pin 37 for bit 1, etc (see the code). The layout below shows which pins are available.

Using the Code

In the code, we first set 8 selected pins into output mode. Then in a loop, we extract current value of each bit of the counter by applying corresponding bit mask and set individual GPIO pin mapped to that bit.

# counter.py
import RPi.GPIO as GPIO
import time

print "=== Binary counter ==="

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD) # access pins by their numbers 

# Configure 8 pins to output mode
GPIO.setup(33, GPIO.OUT) # pin 33 for bit 0
GPIO.setup(37, GPIO.OUT) # pin 37 for bit 1
GPIO.setup(7,  GPIO.OUT)
GPIO.setup(11, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
GPIO.setup(19, GPIO.OUT)
GPIO.setup(21, GPIO.OUT) # pin 21 for bit 7

cnt = 0
print "Press Ctrl-C to exit"

try:
 while True:
 GPIO.output(33, cnt & 0x01) # set bit 0
 GPIO.output(37, cnt & 0x02) 
 GPIO.output(7,  cnt & 0x04)
 GPIO.output(11, cnt & 0x08)
 GPIO.output(13, cnt & 0x10)
 GPIO.output(15, cnt & 0x20)
 GPIO.output(19, cnt & 0x40)
 GPIO.output(21, cnt & 0x80) # set bit 7
 time.sleep(0.1)             # wait 100 msec
 cnt += 1 %  256 # increment counter up to 255, then reset to 0

except KeyboardInterrupt:
 GPIO.cleanup()

If you saved the code in counter.py file, just run this command to start the counter:

python counter.py

And that's it. Happy coding!

8-bit LED Binary Counter

This article offers a simple implementation of the binary counter powered by Raspberry PI3 and 8 LEDs. It is very similar to what was done before for Arduino board in the previous article Connecting an Arduino to a Breadboard to Light Up LEDs. In this project, we will be using Python to program the board.

Posted on 11-09-2018 

Comment:

To comment you must be logged in members.

Files with category

  • How to Display a Battery Charge Level in Xamarin Forms using Font Awesome

    How to Display a Battery Charge Level in Xamarin Forms using Font Awesome

    View: 36    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Other

    I was building a Xamarin Forms application with an interface that displays the charge level of a battery. I choose to do it with Font Awesome to give uniform aspect to this application with the website the same product has.

  • 8-bit LED Binary Counter

    8-bit LED Binary Counter

    View: 52    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Other

    This article offers a simple implementation of the binary counter powered by Raspberry PI3 and 8 LEDs. It is very similar to what was done before for Arduino board in the previous article Connecting an Arduino to a Breadboard to Light Up LEDs. In...

  • Chat App

    Chat App

    View: 84    Download: 3   Comment: 0

    Category: Android     Fields: none

    This is a Chat App for Android mobile. You can make separate chat with you partner. I'm using Mysql Database and Php code and All APIs are develop on PHP (REST APIs). My whatsApp:+918285672453: Email ID: nirbhayiise@gmail.com

  • Tower Defense 3D

    Tower Defense 3D

    View: 67    Download: 0   Comment: 0

    Category: Android     Fields: Game - Entertainment

    The goal in this game is to protect your territory against the attacking enemies. Place defensive structures on or along their path of attack to prevent them reaching your base. Strategic choice and positioning of defensive elements is an essential...

  • Flap the Bird

    Flap the Bird

    View: 41    Download: 0   Comment: 0

    Category: Android     Fields: Game - Entertainment

    Tap your screen to make the bird fly. While you are flying there are destruction that will stop you. Avoid hitting the floor and flying to high this will deduct your life. You can collect coins and life along the way. For more mobile games and...

  • Bad Santa

    Bad Santa

    View: 55    Download: 0   Comment: 0

    Category: Android     Fields: Game - Entertainment

    This is a simple shooting game where the Bad Santa is shooting the bad snowman and reindeer. You can collect coins and life along the way. For more mobile games and tutorials you can visit this site.

  • Flappy Halloween Game

    Flappy Halloween Game

    View: 49    Download: 0   Comment: 0

    Category: Android     Fields: Game - Entertainment

    Flappy Halloween is a simple game, tap the screen to move the player. Shoot the pumpkin in the ring to gain score. Avoid hitting the flying destructions and falling from the ground. Since the Halloween is coming this game is really perfect to play...

  • Tilt Ball Game

    Tilt Ball Game

    View: 40    Download: 0   Comment: 0

    Category: Android     Fields: Game - Entertainment

    This game is simple you need to tilt your device to make the ball move in your own desired direction. Reach the finish line before the time ends and move to the next level.

 
File suggestion for you
Loading...
File top downloads
Loading...
Loading...
Codetitle - library source code to share, download the file to the community
Copyright © 2018. All rights reserved. codetitle Develope by Vinagon .Ltd