Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from microbit import *
- import radio
- HasSent = False
- OponentVal = 0
- rock = Image("00000:"
- "09990:"
- "99999:"
- "09990:"
- "00000")
- paper = Image("99999:"
- "99999:"
- "99999:"
- "99999:"
- "99999")
- scissors = Image("09090:"
- "09090:"
- "00900:"
- "09090:"
- "90009")
- #Functions and code
- def printStr( str ):
- "This prints a passed string into this function"
- display.scroll (str)
- return
- def run():
- radio.on()
- ShowRock(1000)
- ShowPaper(1000)
- ShowScissors(1000)
- def ShowRock( time ):
- display.show(rock)
- sleep(time)
- display.clear()
- def ShowPaper( time ):
- display.show(paper)
- sleep(time)
- display.clear()
- def ShowScissors( time ):
- display.show(scissors)
- sleep(time)
- display.clear()
- def ShowOponent():
- if OponentVal == "1" or OponentVal == "2" or OponentVal == "3":
- if OponentVal == "1":
- ShowRock(1000)
- if OponentVal == "2":
- ShowPaper(1000)
- if OponentVal == "3":
- ShowScissors(1000)
- #loop
- def loop():
- global HasSent
- global OponentVal
- inputPin = radio.receive()
- #Anti signal block/DDos
- if str(inputPin) == "0" or str(inputPin) == "1" or str(inputPin) == "3":
- ConInput = str(inputPin)
- if conInput == "0":
- if HasSent == True:
- #Display stuff
- OponentVal = ConInput
- ShowOponent()
- return
- else:
- OponentVal = ConInput
- elif conInput == "1":
- if HasSent == True:
- #Display stuff
- OponentVal = ConInput
- ShowOponent()
- return
- else:
- OponentVal = ConInput
- elif conInput == "2":
- if HasSent == True:
- #Display stuff
- OponentVal = ConInput
- ShowOponent()
- return
- else:
- OponentVal = ConInput
- elif conInput == "3":
- if HasSent == True:
- #Display stuff
- OponentVal = ConInput
- ShowOponent()
- return
- else:
- OponentVal = ConInput
- if button_a.is_pressed() and button_b.is_pressed():
- #Both buttons
- radio.send("3")
- HasSent = True
- ShowOponent()
- elif button_a.is_pressed():
- #button 1
- radio.send("1")
- HasSent = True
- ShowOponent()
- elif button_b.is_pressed():
- #button 2
- radio.send("2")
- HasSent = True
- ShowOponent()
- else:
- radio.send("0")
- #RunningStuff
- run()
- while True:
- loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement