O'Reilly logo
  • Alexander Jaworowski thinks this is interesting:

In C++ or other object-oriented languages, to inject the dependency, we pass a new I/O pin handler object to the LED whenever a button is pressed. The LED module would never know anything about which pin it was changing or how it was doing so. The variables to hide this are set at initialization time (but do remember that these are variables, consuming RAM and cluttering the code).


Cover of Making Embedded Systems


Where do we decide which handler? We have a global variable for number of counts. We could use enum and the counter could be used as index:

enum led_color {red, green, blue};