(Sorry for the long haitus of posts, I've been dealing with some health issues that appear to be going away finally.)
NOW.....
One of the most ePIc Pi-days is here today! 3-14-15!!! What better way to celebrate this Pi-Day than to program your Raspberry Pi in Python to display digits of Pi.
We are going to accomplish this through 4 LEDs which together will display the binary representation of the decimal digits of Pi.
Here is the key for the 4 LEDs to display digits: (1 for on, 0 for off)
(led 1, led 2, led 3, led 4)
0 = (0, 0, 0, 0)
1 = (1, 0, 0, 0)
2 = (0, 1, 0, 0)
3 = (1, 1, 0, 0)
4 = (0, 0, 1, 0)
5 = (1, 0, 1, 0)
6 = (0, 1, 1, 0)
7 = (1, 1, 1, 0)
8 = (0, 0, 0, 1)
9 = (1, 0, 0, 1)
We want to display in order 3 then 1 then 4 then 1 then 5 ....
Here is the photo of the completed project:
Here is the wiring set up:
# Script to display the digits of pi in binary on leds
import os
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(7,GPIO.OUT)
GPIO.setup(11,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(15,GPIO.OUT)
number_seq = 31415926535897932384
number_list = list(str(number_seq))
for n in number_list:
if n == '0':
time.sleep(1)
if n == '1':
GPIO.output(7, GPIO.HIGH)
time.sleep(1)
GPIO.output(7, GPIO.LOW)
if n == '2':
GPIO.output(11, GPIO.HIGH)
time.sleep(1)
GPIO.output(11, GPIO.LOW)
if n == '3':
GPIO.output(7, GPIO.HIGH)
GPIO.output(11, GPIO.HIGH)
time.sleep(1)
GPIO.output(7, GPIO.LOW)
GPIO.output(11, GPIO.LOW)
if n == '4':
GPIO.output(13, GPIO.HIGH)
time.sleep(1)
GPIO.output(13, GPIO.LOW)
if n == '5':
GPIO.output(7, GPIO.HIGH)
GPIO.output(13, GPIO.HIGH)
time.sleep(1)
GPIO.output(7, GPIO.LOW)
GPIO.output(13, GPIO.LOW)
if n == '6':
GPIO.output(11, GPIO.HIGH)
GPIO.output(13, GPIO.HIGH)
time.sleep(1)
GPIO.output(11, GPIO.LOW)
GPIO.output(13, GPIO.LOW)
if n == '7':
GPIO.output(7, GPIO.HIGH)
GPIO.output(11, GPIO.HIGH)
GPIO.output(13, GPIO.HIGH)
time.sleep(1)
GPIO.output(7, GPIO.LOW)
GPIO.output(11, GPIO.LOW)
GPIO.output(13, GPIO.LOW)
if n == '8':
GPIO.output(15, GPIO.HIGH)
time.sleep(1)
GPIO.output(15, GPIO.LOW)
if n == '9':
GPIO.output(7, GPIO.HIGH)
GPIO.output(15, GPIO.HIGH)
time.sleep(1)
GPIO.output(7, GPIO.LOW)
GPIO.output(15, GPIO.LOW)
GPIO.cleanup()
Yay!!!!
HAPPY PI DAY!!!