CONTENTS

Acknowledgments

1     Introduction

Plug Me In!

History

What Can It Do?

micro:bit versus Raspberry Pi and Arduino

So What Is Programming?

Why MicroPython?

Summary

2     Getting Started

MicroPython Editors

Online Editor

Installing micro:bit Programs Using Windows

Installing micro:bit Programs Using a Mac

Installing micro:bit Programs Using Linux

Saving and Loading Programs

The Mu Editor

Installing Mu on Windows

Installing Mu on a Mac

Installing Mu on Linux

Using Mu

The REPL

Downloading This Book’s Programs

Summary

3     MicroPython Basics

Numbers

Variables

Strings

Converting Numbers to Strings

Programs

Looping Forever

for Loops

ifs and elses

More on while

Timer Example

Summary

4     Functions

What Are Functions?

Parameters

Global Variables

Return Values

Advanced Parameters

Summary

5     Lists and Dictionaries

Lists

Message Board Example

The Lowdown on Lists

Accessing Elements of a List

Adding to a List

Deleting from a List

Joining Lists Together

Strings as a List of Characters

Dictionaries

An Example

Dictionaries in Detail

Accessing Elements of a Dictionary

Adding Items to a Dictionary

Summary

6     Writing Your Own Programs

Writing Software

Keep It Simple

Spikes and the REPL

Versioning

Comments

Refactoring

State Machine Design

Revisiting the Timer Example

A State Machine Framework

Switching Between States

Adding Code to the SET State

Adding Code for the RUN State

Adding Code for the ALARM State

Debugging

More Python

Formatting

Exception Handling

File System

Summary

7     Modules and Classes

Built-in Modules

Importing Modules

Classes and Instances

Inheritance

Making Simple Modules

Making a Module That Uses a Class

Module and Class Definition

Methods

Using the Module

Modules from the Community

Summary

8     The LED Display

Controlling Individual LEDs

Scrolling Text

Showing Text

Showing an Image

Animation

Racing Game

Summary

9     micro:bit Sensors

Buttons Revisited

Gestures

Raw Accelerometer Data

Magnetometer

Processor Temperature

Touch

Summary

10     Connecting Electronics

Battery Power

USB Power Pack

3 V Battery Pack

Battery Life

micro:bit Operating Voltage

GPIO Pins 0, 1, and 2

Alligator Clip Leads

Digital Outputs

Analog Outputs

Digital Inputs

Analog Inputs

Power Out

Sound Output

Alligator Clip to Audio Socket

Amplifier Modules

Updating the Alarm Project

Music

Speech

Neopixels

The Edge Connector

Pinout

Breakout Boards and Kits

Disabling Hardware

Summary

11     Radio and Communications

Basic micro:bit-to-micro:bit Communication

Messaging Different Users

Advanced Radio Settings

Computer-to-micro:bit Communication

Remote Control of Your micro:bit Using Python

Python on Your Computer

Getting Bitio

Installing the Resident Program

Using Bitio from the Console

Summary

12     JavaScript Blocks Editor

The Editor

Getting Started

Events

Variables and Loops

Magnetometer Example

Summary

A     MicroPython Reference

Language Contructs

Comparisons

Numbers

Strings

Lists

Dictionaries

Type Conversions

B     Hardware

micro:bit Edge Connector Pinout

Suppliers and Manufacturers

Components

Hardware

Kits

Basic Components

Modules and Expansion Boards

Index