Chapter 8. Input and Sensing

It is important for a device to react to interactions from users or changes in its environment. Such interactions are at the core of the device’s nonprogrammer user experience. For example, shaking the device to reset the state of the program, using the light sensor to change the intensity of the LEDs, or pressing a button to cycle through a series of options are all interactions that rely on the device processing input or sensing changes in its environment.

The devices described in this book do not have keyboards, mice, or touchscreens like traditional computing devices. So how are we to interact with them? Typing Python commands into a REPL might be fun for programmers, but this doesn’t address the needs of nontechnical users who need to communicate intents, instructions, or decisions in a manner that is intuitive, context sensitive, and perhaps even entertaining. Therefore, it’s important to consider how MicroPython works with input and sensors.

Collectively, the devices covered in this book have a wide variety of input and sensing capabilities available to them. Some, like the ESP8266/32-based devices, are limited only to one or two buttons; others, like the Circuit Playground Express and micro:bit, have all sorts of components through which users can interact with the device. In all cases, it is possible to connect external sensors and peripherals to the boards via GPIO pins, and the general prinicples of working with such hardware can be transferred ...

Get Programming with MicroPython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.