MrYsLab / s2m

Scratch to micro:bit bridge.
https://mryslab.github.io/s2m/
GNU Affero General Public License v3.0
35 stars 19 forks source link

"Shaken?" block does not give "true" even if micro:bit is shaken #6

Closed champierre closed 6 years ago

champierre commented 6 years ago

"Shaken?" block does not give "true" even if micro:bit is shaken.

MrYsLab commented 6 years ago

The shaken state is momentary. To see what I mean, click the check mark next to the shaken block, shake the board and see if it goes from false to true.

champierre commented 6 years ago

Here is the demo movie showing what I did. Scratch cat should say Hello if the board is shaken, but it did not.

https://www.youtube.com/watch?v=bKzX7lHCGoc

I tried with Micro:bit block editor, and it worked fine, so I believe my board does not have functional problem.

Could it be Mac issue?

MrYsLab commented 6 years ago

I have been testing for Windows and Linux (no Mac here) using VirtualBox since I use Linux as my native operating system and did not see the problem. This tends to run much slower than on a computer running Windows as its native operating system.

So, I tried running your example on a very fast native Windows 10 laptop and got the same results as you did.

I added a short delay to solve the problem.

shake_delay

The HTTP Scratch specification causes some timing issues because the reporter blocks are not executed as one would think, but Scratch sends a "poll" command asynchronously at about 30 times per second. Syncing the actual event to the poll is a problem and adding the short delay solves the issue here and hopefully will solve it for you as well.

I will add a note about this to the User's Guide.

Let me know if things work better with the delay.

champierre commented 6 years ago

After I tried so many times, I found that Shaken? was triggered when I shaked the board vertically. When I shaked the board horizontally, it was difficult to trigger. In my environment, it seems that inserting "wait 0.1 secs" block did not matter to the result.

MrYsLab commented 6 years ago

Thanks - you are correct about how the board needs to be shaken for s2m. I will be revisiting this and may change the program on the micro:bit. I am able to get the raw accelerometer values but if I use the micro:bit calls to request gestures instead, there appears to be some conflict with retrieving and sending that data over the serial bus - it does not always appear to be correct. There may be some timing conflict on the micro:bit in this case.

I will update the User's Guide to make Shaken? clear.