The objective of this step is the following:

  • Introduce home-made abstraction in C code

The blinking LED example, abstracted

The blinking LED example is a good example of a finite state machine. The LED goes from an on state to an off one, indefinitely.

The idea is to reify in the host language the associated abstraction. We propose here a functional approach, where each state is designed as a function, and moving from one state to the other is modelled by a call to the associated function. The initial state is the one called by the main loop.

void state_on() {
digitalWrite(led, HIGH);
_delay_ms(1000);
state_off();
}

void state_off() {
digitalWrite(led, LOW);
_delay_ms(1000);
state_on();
}


Expected work

  • Modify the given code to support interaction with the button. Instead of blinking, the led will switch from one state to the other when the button is pressed.
  • Identify the right computation model associated with the 7-segment display use case.
  • Implement it in main.c (states signature are declared in fsm.h)

Stepback Questions

  • Does introducing a convention solve the readability issue?
  • How to extend an app with a new feature? Does the approach prevent one to perform invasive changes in the existing behaviour to introduce a new one?
  • How to extend the code so that to support new features, e.g., memory-less tasks, state-full tasks, different frequencies?