Programming with MicroPython by Nicholas H. Tollervey
Author:Nicholas H. Tollervey
Language: eng
Format: epub, pdf
Publisher: O'Reilly Media
Published: 2017-10-11T04:00:00+00:00
from microbit import * x = 2 y = 2 sensitivity = 50 pause = 90 fade = 2 while True: roll = accelerometer.get_x() yaw = accelerometer.get_y() if roll < -sensitivity: x = max(0, x - 1) elif roll > sensitivity: x = min(4, x + 1) if yaw < -sensitivity: y = max(0, y - 1) elif yaw > sensitivity: y = min(4, y + 1) for i in range(5): for j in range(5): brightness = max(0, display.get_pixel(i, j) - fade) display.set_pixel(i, j, brightness) display.set_pixel(x, y, 9) sleep(pause)
The important lines are where we call accelerometer.get_x and accelerometer.get_y. There is also a notion of sensitivity such that movement won’t register in a direction until some threshold is reached (in the example, this is given the arbitrary value 50, arrived at through experimentation). This is because the accelerometer is very sensitive, and humans do not have such fine-grained motor skills to work with such sensitive devices. The threshold means we have to tip the device in one direction or another more than enough for us humans to be able to register the difference. When some aspect of the hardware is used to interact with humans, there often needs to be some sort dampening of sensitivity via thresholds or bucketing values so the device is both manageable and usable.
In the case of an accelerometer, such interactions are reminiscent of the Wii remote and other similar peripherals for console games used to control player characters and other game-related assets. The tilting and movement of an accelerometer is a useful metaphor for controlling an aspect of some other thing (such as the position of a pixel). An accelerometer is also useful if you need to log the forces applied to an object, such as a model rocket.
Another use of the accelerometer is to detect gestures, such as shake, freefall, or face up. Such gestures are useful from a user interaction point of view since they can also represent states or instructions. For example, shake may mean something negative like “cancel and restart the game”; freefall is probably an indication that the device is in the process of being dropped, so prepare for a crash landing; and face up may just mean display something (since you look down upon the display of the micro:bit) in a similar manner to the way mobile phones activate their screens when you take them away from your ear to look at them.
Currently, only the micro:bit has built-in support for gestures. The following example demonstrates how they can be used:
Download
Programming with MicroPython by Nicholas H. Tollervey.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Automotive | Engineering |
Transportation |
Whiskies Galore by Ian Buxton(41488)
Introduction to Aircraft Design (Cambridge Aerospace Series) by John P. Fielding(32852)
Small Unmanned Fixed-wing Aircraft Design by Andrew J. Keane Andras Sobester James P. Scanlan & András Sóbester & James P. Scanlan(32533)
Craft Beer for the Homebrewer by Michael Agnew(17902)
Turbulence by E. J. Noyes(7659)
The Complete Stick Figure Physics Tutorials by Allen Sarah(7096)
Kaplan MCAT General Chemistry Review by Kaplan(6545)
The Thirst by Nesbo Jo(6405)
Bad Blood by John Carreyrou(6245)
Modelling of Convective Heat and Mass Transfer in Rotating Flows by Igor V. Shevchuk(6200)
Learning SQL by Alan Beaulieu(5994)
Weapons of Math Destruction by Cathy O'Neil(5778)
Man-made Catastrophes and Risk Information Concealment by Dmitry Chernov & Didier Sornette(5585)
Digital Minimalism by Cal Newport;(5319)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5143)
iGen by Jean M. Twenge(5125)
Secrets of Antigravity Propulsion: Tesla, UFOs, and Classified Aerospace Technology by Ph.D. Paul A. Laviolette(4858)
Design of Trajectory Optimization Approach for Space Maneuver Vehicle Skip Entry Problems by Runqi Chai & Al Savvaris & Antonios Tsourdos & Senchun Chai(4805)
Electronic Devices & Circuits by Jacob Millman & Christos C. Halkias(4698)
