Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to control micro:bit accelerometer with mouse #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

notexactlyawe
Copy link

Firstly, thanks for making this, it's been a huge help in past workshops!

I have a workshop that gets people to build a snake game on micro:bit using the accelerometer. If they tilt the device forward, then the snake will move up the screen; if they tilt it to the left then the snake will move in a leftwards direction.

While this code can be simulated with this repository, it can be a bit inconvenient to have to adjust each accelerometer axis separately to make the snake move. This PR adds in the ability to change the accelerometer X and Y according to the mouse position.

Screenshot from 2020-05-09 22-10-05

I've added a checkbox to the accelerometer tab that allows this to be turned on and off since it would be surprising behaviour without explicitly requesting it. When the checkbox is ticked, the user can move the mouse within the #microbit element and the accelerometer values will change. In the snake example, it looks like the snake is trying to follow the mouse, which feels intuitive.

I tried to add animations which you can test out in the mouse-accel-anim branch but I didn't like how they turned out. They made the screen more difficult to see, and it was hard to differentiate left from right and up from down.

If you want to test this code with the snake program, it's available in ears-edi/microbit-snake.

Let me know what you think!

@notexactlyawe
Copy link
Author

One extra note, I've put it up on my domain (using GH pages) so you can play around with it:

https://www.cameronmacleod.com/createwithcode/

Sliders now move along with the value
Value update is debounced to reduce CPU usage (30fps)
Value spans have minimum width to prevent them expanding and
contracting endlessly, which is visually distracting
Ran mb.css through a CSS validator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant