Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let Dist = 0
- // Setup Variable Config
- let MaxDist = 25
- let PinLightArray = [DigitalPin.P1, DigitalPin.P2]
- let Sound = soundExpression.hello;
- let Delay = 5
- let ForLoopDeplay = 1
- let SoundDelay = 0.5
- let SoundMakingDelay = 1
- // Main Code
- Delay = Delay * 1000
- SoundMakingDelay = SoundMakingDelay * 1000
- SoundDelay = SoundDelay * 1000
- ForLoopDeplay = ForLoopDeplay * 1000
- const TurnLight = (signal: number) => {
- for (let light of PinLightArray) {
- pins.digitalWritePin(light, signal);
- basic.pause(ForLoopDeplay);
- }
- }
- // Dist checking function
- basic.forever(function () {
- Dist = sonar.ping(
- DigitalPin.P14,
- DigitalPin.P15,
- PingUnit.Centimeters
- )
- if (Dist > 0 && Dist <= MaxDist) {
- control.inBackground(function() {
- while (Dist > 0 && Dist <= MaxDist)
- {
- music.play(music.createSoundExpression(WaveShape.Sine,
- 5000, 5000, 255, 255, 500,
- SoundExpressionEffect.None, InterpolationCurve.Linear
- ),
- music.PlaybackMode.UntilDone)
- basic.pause(SoundMakingDelay)
- }
- })
- control.inBackground(function(){TurnLight(0);});
- IdeaKitMaker.Servo(IdeaKitMaker.Servos.S1, 140)
- basic.pause(Delay)
- } else {
- control.inBackground(function(){TurnLight(1);});
- IdeaKitMaker.Servo(IdeaKitMaker.Servos.S1, 30)
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement