Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 11_dice.py: added missing functions #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions 11_dice.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
from random import randint


# Set up pins
SDI = 17
Expand All @@ -12,9 +14,6 @@
# Define a segment code from 0 to 6 in Hexadecimal
SegCode = [0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d]

# Used to record button press
flag = 0

def print_msg():
print 'Program is running...'
print 'Please press Ctrl+C to end the program...'
Expand All @@ -24,8 +23,7 @@ def setup():
GPIO.setup(SDI, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(RCLK, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(SRCLK, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(TouchPin, GPIO.IN)
GPIO.add_event_detect(TouchPin, GPIO.RISING)
GPIO.setup(TouchPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# Shift the data to 74HC595
def hc595_shift(dat):
Expand All @@ -38,10 +36,22 @@ def hc595_shift(dat):
time.sleep(0.001)
GPIO.output(RCLK, GPIO.LOW)

def randomISR():
if GPIO.event_detect(TouchPin):
flag = 1
def loop():
while True:
if not GPIO.input(TouchPin):
hc595_shift(SegCode[randint(0,5)])
time.sleep(2.0)

hc595_shift(SegCode[randint(0,5)])
time.sleep(0.060)

def destroy(): #When program ending, the function is executed.
GPIO.cleanup()

def main():
if __name__ == '__main__': #Program starting from here
print_msg()

setup()
try:
loop()
except KeyboardInterrupt:
destroy()