jon black

"I am in a charming state of confusion"

Arduino finite state machine library

Introducing arduino-fsm, a library that makes it easy to use a finite state machine in an Arduino project.

Design

This library is composed of two classes: Fsm and State:

State Represents a state in the state machine. A state has two callback functions associated with it: on_enter and on_exit, which are called when the state is entered into and exited from, respectively.
Fsm Represents the state machine. Transitions are added using the add_transition function. This function takes pointers to two states, an event id, and a callback to a function that's called when the transition takes place. Calling trigger with the event id invokes the transition, but only if the Fsm is in the start state, otherwise nothing happens.

Tutorial

First create the Fsm and State instances at the top of your source file.

#include <Fsm.h>

#define FLIP_LIGHT_SWITCH 1
Fsm fsm;  
State

Arduino menu system library

Introducing the arduino-menusystem library that makes it easy to incorporate a menu system into an Arduino project.

Design

The library is implemented according to the composite design pattern. When using this library you need to create Menu's, MenuItem's, and a single MenuSystem.

Menu A Menu represents an item in the menu that contains other Menu's and MenuItem's. Use add_menu_item() and add_menu() to build its contents.
MenuItem A MenuItem represents an action. When select() is called the MenuItem's callback function is called.
MenuSystem The MenuSystem contains the core functions for interacting with the menu system: next(), prev(), select(), and back().

Tutorial

First create the various Menu's, MenuItem's, and MenuSystem at the top


The Internet of Unsupported Things

There are an insane number of devices connected to The Internet, and it's growing at a crazy rate. In 2012 Cisco estimated around 8.7 billion, and that figure in 2015 jumps to a massive 15 billion.

Think about that for a second.

In three years, the number of devices has grown 58%. If that were to continue, in 15 years there'd be a staggering 146.1 billion devices!

You're living at the dawn of The Internet of Things. Your fridge. Your toaster. Your thermostat. Your car. You washing machine. Your dishwasher. Even your lightbulbs will be connected.

On the one hand this is really cool. You can control your lights with your phone, and by mining all the data from these devices, perhaps your food shopping can be ordered by your fridge, or your electricity meter can find a cheaper electricity plan? Even your baby's nappy can tweet when


How to distribute GPS points evenly

In How to compare GPS tracks I showed how the Needleman-Wunsch algorithm, originally designed for aligning DNA and protein sequences, can be used to compare GPS tracks.

The method I introduced relies on pre-processing the GPS file so that all points are evenly distributed to reduce noise in the data set, but I didn't cover how that's done.

Trace the path

Starting from the first point, the path is followed and the great-circle distance between each point is accumulated until it exceeds the desired distribution distance.

When the distance has been exceeded, a new point is interpolated between the current point and the previous point.

gpxpy has a function for moving points when given an angle and a distance in meters. The distance is the accumulated distance minus the required distance. gpxpy doesn't have a function for calculating the angle, otherwise known as initial bearing, between two points. Using the


Everyone's a hacker

As an impressionable teenager my image of a hacker was of someone who could use a computer to do whatever they pleased. Not only in the sense that they didn't care for boundaries but also that the boundaries couldn't stop them.

Nothing epitomised this more than the ATM hack by John Conner in the film Terminator 2.

Countless films and TV series have portrayed the hacker in a similar light: Neo in The Matrix, David Lightman in War Games, and Chloe O'Brian in 24, which is why the controvertial statement by Paul Graham disappoints me so much:

No, the problem is these women are not by the time they get to 23... Like Mark Zuckerberg starts programming, starts messing about with computers when he's like 10 or whatever. By the time he's starting Facebook he's a hacker, and so he looks at the world through hacker eyes.

Mark Zuckerberg made