Advertisement
SigmaBoy456

MicroBIt SmartHome #423

Feb 10th, 2025 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. // Setup Variable Config
  2. let MaxDist = 30;
  3. let PinLightArray = [
  4.     DigitalPin.P1,
  5.     DigitalPin.P2
  6. ];
  7. let Sound = soundExpression.hello;
  8. let Delay = 1;
  9. let ForLoopDeplay = 1;
  10. // Main Code
  11. Delay = Delay * 100;
  12. ForLoopDeplay = ForLoopDeplay * 100;
  13. const TurnLight = (signal: number) => {
  14.     for (let light of PinLightArray) {
  15.         pins.digitalWritePin(light, signal);
  16.         basic.pause(ForLoopDeplay);
  17.     }
  18. }
  19. basic.forever(function () {
  20.     let Dist = sonar.ping(DigitalPin.P14, DigitalPin.P15, PingUnit.Centimeters);
  21.     if (Dist > 0 && Dist <= MaxDist) {
  22.         TurnLight(1);
  23.         music.play(music.builtinPlayableSoundEffect(Sound), music.PlaybackMode.UntilDone);
  24.         IdeaKitMaker.Servo(IdeaKitMaker.Servos.S1, 110);
  25.     } else {
  26.         TurnLight(0);
  27.         IdeaKitMaker.Servo(IdeaKitMaker.Servos.S1, 30);
  28.     }
  29. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement