Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. from microbit import *
  2. import music
  3.  
  4. dog = Image("99000:99999:09999:09009:09009") #number = intensity of light for the image
  5. display.show(dog) #custom pic
  6. sleep(1000)
  7.  
  8. counter = 0 ##starting incrementation for later in loop
  9. while True:
  10.  
  11. LightIntensity = pin0.read_analog() #reads the light from phototransistor and stores it as variable
  12. if LightIntensity < 100:
  13. display.show(Image.ASLEEP)
  14. elif button_a.is_pressed() and button_b.is_pressed():
  15. display.show(Image.ANGRY)
  16. music.pitch(440,1000)
  17. sleep(1000)
  18. music.pitch(440,-1)
  19. sleep(1000)
  20. music.stop()
  21. elif button_a.is_pressed(): # button_a is simulating feeding the animal
  22. display.show(Image.HAPPY)
  23. sleep(2000)
  24. elif button_b.is_pressed(): # button_b is simulating petting the animal
  25. display.show(dog)
  26. sleep(3000)
  27. count = button_b.get_presses() #counts how many times b was pressed in 3 seconds
  28. if count <= 2:
  29. display.show(Image.HEART_SMALL) #small heart because not many pets
  30. sleep(2000)
  31. elif count > 2:
  32. display.show(Image.HEART) #big heart because lots of pets
  33. sleep(2000)
  34.  
  35. else:
  36. if counter < 1500:
  37. display.show(dog)
  38. elif counter >= 1500 and counter <= 3000: ##alternating between dog and sad picture every 1000 cycles
  39. display.show(Image.SAD)
  40. else:
  41. counter = 0 ##reset counter
  42. counter = counter + 1 ##incrementation for cycles
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement