• What I think happens is - since you do not debounce your button - that multiple play() run at the same time, and due to interference with time/phase constantly shifting funny sounds... (to verify that, put in our current code var cnt = 0; before the line function play(), and cnt++ after it. Then you upload the code and press the button. When it has finished playing, enter in console cnt and tell me what you got!

    Therefore, do something like this for watching your button:

    setWatch(play, BTN1, { repeat: false, edge:'xxxxx' , debounce:50});
    

    xxxxx is either rising or falling - both is working (if you do not hold on to the button until play has finished).

    You put this line as line 27 and you also insert it into your stop after line 14 (in which you switch your LED1 off).

    When this is working - with xxxx the way that the play starts only after you have released the button - you can then make it stop when pressing and releasing the button while it is playing.

    Looking forward to hear from you!

    PS: I did not work with files yet on Espruino, but I wonder if you need to do something like close(), do you?

About

Avatar for allObjects @allObjects started