bromagosa / Snap4Arduino

Binding Snap! and Arduino together
http://snap4arduino.rocks
GNU Affero General Public License v3.0
134 stars 85 forks source link

distance sensor not working #318

Closed woronin closed 1 year ago

woronin commented 1 year ago

When connecting an ultrasonic distance sensor, an error pops up. This error began to appear only in new versions - 7.0.4 If you run the same program in version 6.2, then there are no errors image 7_04_distant2.xml.tar.gz

jguille2 commented 1 year ago

Hi @woronin

This is not a bug. I explain the current operation and the different possibilities:

  1. Snap! (and then Snap4Arduino) decided not to execute generic javascript code without the user's permission, to prevent bad practices (especially considering the execution of projects that are made directly from the web, to test them, without seeing the code or knowing who has done). And yes, this happened at version 7. But you only have to go to Snap4Arduino settings menu, and click to allow "Javascript extensions". And that's all.

allowJs

  1. If you want to avoid this requeriment (having to enable the extensions each time) you still have two options: 2.1 You have libraries that have this "ping" block implemented. I use SA5Firmata, and then, this SA5Firmata library has this block (and others: tone, pulses, nunchuck and dht11). You can use that "ping" block or you can use the generic "pulseIn" block to build your own.

pingBlock

2.2 If you use another Firmata code to implement this ping option, you can take a look at the Snap4Arduino "primitives" because we set different "general used options" to allow these "javascript known code" without extensions. These functions are at https://github.com/bromagosa/Snap4Arduino/blob/master/src/s4a/extensions.js#L117-L215

That's all. I close this issue, but you continue if needed with questions or suggestions.

Joan