Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from microbit import *
- import music
- dog = Image("99000:99999:09999:09009:09009") #number = intensity of light for the image
- display.show(dog) #custom pic
- sleep(1000)
- counter = 0 ##starting incrementation for later in loop
- while True:
- LightIntensity = pin0.read_analog() #reads the light from phototransistor and stores it as variable
- if LightIntensity < 100:
- display.show(Image.ASLEEP)
- elif button_a.is_pressed() and button_b.is_pressed():
- display.show(Image.ANGRY)
- music.pitch(440,1000)
- sleep(1000)
- music.pitch(440,-1)
- sleep(1000)
- music.stop()
- elif button_a.is_pressed(): # button_a is simulating feeding the animal
- display.show(Image.HAPPY)
- sleep(2000)
- elif button_b.is_pressed(): # button_b is simulating petting the animal
- display.show(dog)
- sleep(3000)
- count = button_b.get_presses() #counts how many times b was pressed in 3 seconds
- if count <= 2:
- display.show(Image.HEART_SMALL) #small heart because not many pets
- sleep(2000)
- elif count > 2:
- display.show(Image.HEART) #big heart because lots of pets
- sleep(2000)
- else:
- if counter < 1500:
- display.show(dog)
- elif counter >= 1500 and counter <= 3000: ##alternating between dog and sad picture every 1000 cycles
- display.show(Image.SAD)
- else:
- counter = 0 ##reset counter
- counter = counter + 1 ##incrementation for cycles
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement