Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #config Variable
- ArrPinLight = [
- DigitalPin.P1,
- DigitalPin.P2
- ]
- delay = 1
- forloopdelay = 1
- MaxDist = 10
- Sound = soundExpression.hello
- music.set_volume(255)
- #function set
- delay = delay * 100
- forloopdelay = forloopdelay * 100
- def TurnLight(signal : int):
- global forloopdelay, ArrPinLight
- for i in ArrPinLight:
- pins.digital_write_pin(i, signal)
- basic.pause(forloopdelay)
- def on_forever():
- global MaxDist, delay, Sound
- dist = sonar.ping(DigitalPin.P14, DigitalPin.P15, PingUnit.CENTIMETERS)
- if dist > 0 and dist <= MaxDist:
- TurnLight(0)
- music.play(music.builtin_playable_sound_effect(Sound), music.PlaybackMode.UNTIL_DONE)
- else:
- TurnLight(1)
- basic.pause(delay)
- basic.forever(on_forever)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement