# jon black

"I am in a charming state of confusion"

Rendering a menu in arduino-menusystem version 2.1.1 isn't dictated by the API. For example, in the current_menu.ino example the menu is rendered in loop():

void loop()
{
Serial.println("");

{
Serial.print(cp_m_comp->get_name());

Serial.print("<<< ");

Serial.println("");
}

// Code ommitted
}


There are two problems with this approach:

1. Complex decision blocks would be needed to render each MenuComponent type differently, resulting in code that's difficult to read and maintain;
2. It's not obvious how the menu system should be rendered; the API provides

The Arduino IDE leaves a lot to be desired. Granted, it's easy for beginners to build and upload sketches, but as a text-editor it makes you want to smash your keyboard against your monitor. Repeatedly.

Files open in new windows instead of a tab, and there are no advanced features like auto-complete; did I mention it looks like a relic from the Windows 95 era?

This article describes how you can free yourself from the shackles of the Arduino IDE and program your Arduino using vim.

# arduino-makefile

arduino-makefile by Sudar Muthu is a great project that allows you compile, upload, and monitor the serial port using a simple makefile.

How simple you ask? 4 lines! Seriously. And one of those is blank!

Let's work through an example together, from scratch. Let's create a makefile for the legendary Blink sketch.

## 1. Install the Arduino IDE

The Arduino IDE is still required

Beginner Arduino programs tend to focus on a single goal, such as blinking an LED or spinning a servo, where the timing is controlled using delay; the famous blink sketch is a prime example:

void setup() {
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}


This works well for single tasks like blinking an LED; however, delay prevents multiple tasks from running concurrently. We can easily add another LED to the blink sketch and have it blink in time with the existing LED...

void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
delay(1000);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
delay(1000);
}


...but if we want the LED's to blink at different rates, where for example the first LED stays on for three seconds and the second stays on for two seconds, we'll find that delay pauses

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

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