Advertisement
SigmaBoy456

JS smartsave #313

Feb 14th, 2025
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let Dist = 0
  2. // Setup Variable Config
  3. let MaxDist = 25
  4. let PinLightArray = [DigitalPin.P1, DigitalPin.P2]
  5. let Sound = soundExpression.hello;
  6. let Delay = 5
  7. let ForLoopDeplay = 1
  8. let SoundDelay = 0.5
  9. let SoundMakingDelay = 1
  10. // Main Code
  11. Delay = Delay * 1000
  12. SoundMakingDelay = SoundMakingDelay * 1000
  13. SoundDelay = SoundDelay * 1000
  14. ForLoopDeplay = ForLoopDeplay * 1000
  15.  
  16. const TurnLight = (signal: number) => {
  17.     for (let light of PinLightArray) {
  18.         pins.digitalWritePin(light, signal);
  19.         basic.pause(ForLoopDeplay);
  20.     }
  21. }
  22. // Dist checking function
  23. basic.forever(function () {
  24.     Dist = sonar.ping(
  25.     DigitalPin.P14,
  26.     DigitalPin.P15,
  27.     PingUnit.Centimeters
  28.     )
  29.     if (Dist > 0 && Dist <= MaxDist) {
  30.  
  31.         control.inBackground(function() {
  32.             while (Dist > 0 && Dist <= MaxDist)
  33.             {
  34.                 music.play(music.createSoundExpression(WaveShape.Sine,
  35.                 5000, 5000, 255, 255, 500,
  36.                 SoundExpressionEffect.None, InterpolationCurve.Linear
  37.                 ),
  38.                 music.PlaybackMode.UntilDone)
  39.                 basic.pause(SoundMakingDelay)
  40.             }
  41.         })
  42.         control.inBackground(function(){TurnLight(0);});
  43.         IdeaKitMaker.Servo(IdeaKitMaker.Servos.S1, 140)
  44.         basic.pause(Delay)
  45.     } else {
  46.         control.inBackground(function(){TurnLight(1);});
  47.         IdeaKitMaker.Servo(IdeaKitMaker.Servos.S1, 30)
  48.     }
  49. })
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement