Section outline

    • Install the Statemachine Library

      Background information on how to build and install own libraries can be found here.

      • Download the statemachine_START.zip library.
      • In File->Preferences the sketchbook location is given.


        Uncompress the content of the statemachine.zip file into the library folder of the Sketchbook location.
      • An additional subdirectory shall now be available

      Task

      Control the street crossing safely!

      • Understand a single traffic light! How does it work? 
      • Understand the street crossing ... How is it working?
      • What are the different and possible states?






















      Understand Statemachines

      Now, we encode the complete street crossing as one state each. Check the following statechart.


      What is still missing? How could you improve the statechart towards a complete and working street crossing?

       

      Implementation of Statemachines

      This content can be found in statemachine.cpp (the one you copied in the first step)



      Arduino Source Code

      Use the following source code to implement the street crossing control with a statechart!

      • Ampel_00.ino
      • Refactoring
        • Check the 
               uint32_t TRAFFIC_LIGHT_RED = WS2812B.Color(255,   0,   0);
          line.
        • Update all the Ampel1_rot(), Ampel1_rotgelb(), Ampel1_gelb(), ... functions with the above abbreviation to improve the readability of the code.


      Arduino Hardware

      • Check the attachInterrupt() Arduino function.
        • What does this function do?
        • What is an interrupt?
      • Uncomment the attachInterrupt() function in your INO-file.


      ==========================
      Lösung