Skip to content

Instantly share code, notes, and snippets.

@lesp
Created September 19, 2014 21:28
Show Gist options
  • Save lesp/e9fbe5c8aa6982628f72 to your computer and use it in GitHub Desktop.
Save lesp/e9fbe5c8aa6982628f72 to your computer and use it in GitHub Desktop.
Dice Roll
#Function to roll dice
def dice():
roll = randint(1,6)
print(roll)
if roll == 1:
GPIO.output(d1,1)
sleep(3)
GPIO.output(d1,0)
elif roll == 2:
GPIO.output(d1,1)
GPIO.output(d2,1)
sleep(3)
GPIO.output(d1,0)
GPIO.output(d2,0)
elif roll == 3:
GPIO.output(d1,1)
GPIO.output(d2,1)
GPIO.output(d3,1)
sleep(3)
GPIO.output(d1,0)
GPIO.output(d2,0)
GPIO.output(d3,0)
elif roll == 4:
GPIO.output(d1,1)
GPIO.output(d2,1)
GPIO.output(d3,1)
GPIO.output(d4,1)
sleep(3)
GPIO.output(d1,0)
GPIO.output(d2,0)
GPIO.output(d3,0)
GPIO.output(d4,0)
elif roll == 5:
GPIO.output(d1,1)
GPIO.output(d2,1)
GPIO.output(d3,1)
GPIO.output(d4,1)
GPIO.output(d5,1)
sleep(3)
GPIO.output(d1,0)
GPIO.output(d2,0)
GPIO.output(d3,0)
GPIO.output(d4,0)
GPIO.output(d5,0)
elif roll == 6:
GPIO.output(d1,1)
GPIO.output(d2,1)
GPIO.output(d3,1)
GPIO.output(d4,1)
GPIO.output(d5,1)
GPIO.output(d6,1)
sleep(3)
GPIO.output(d1,0)
GPIO.output(d2,0)
GPIO.output(d3,0)
GPIO.output(d4,0)
GPIO.output(d5,0)
GPIO.output(d6,0)
@davipo
Copy link

davipo commented Oct 17, 2015

See my fork for a shorter version, using a list of the LEDs and a loop to handle repetition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment