Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Setup Variable Config
- let MaxDist = 30;
- let PinLightArray = [
- DigitalPin.P1,
- DigitalPin.P2
- ];
- let Sound = soundExpression.hello;
- let Delay = 1;
- let ForLoopDeplay = 1;
- // Main Code
- Delay = Delay * 100;
- ForLoopDeplay = ForLoopDeplay * 100;
- const TurnLight = (signal: number) => {
- for (let light of PinLightArray) {
- pins.digitalWritePin(light, signal);
- basic.pause(ForLoopDeplay);
- }
- }
- basic.forever(function () {
- let Dist = sonar.ping(DigitalPin.P14, DigitalPin.P15, PingUnit.Centimeters);
- if (Dist > 0 && Dist <= MaxDist) {
- TurnLight(1);
- music.play(music.builtinPlayableSoundEffect(Sound), music.PlaybackMode.UntilDone);
- IdeaKitMaker.Servo(IdeaKitMaker.Servos.S1, 110);
- } else {
- TurnLight(0);
- IdeaKitMaker.Servo(IdeaKitMaker.Servos.S1, 30);
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement