-
Notifications
You must be signed in to change notification settings - Fork 5
Understanding the code
This page will try to explain how the arduino code works. It was split in several files for a better division of responsibilities. Each file (or class) is responsible of a specific task.
For instance the class Display read light value out of the Sensor class. But Display has no idea how the sensor is read. It could be a simple analog sensor or a I2C sensor. At the end, Display does not really care. It's the job of Sensor to know how to get the light value.

In this diagram on can see all the classes of this software. The white diamond indicate that the class has a reference to another. For instance display has a reference to TimeManager, Sensor and AbstractLayout.
The white arrow indicate that a class specify another. For the wordclock we use this for the layouts. The AbstractLayout class define the required functions for Display but does not implement them. The concrete implementation of a layout is defined in the specific language file. Basically, Display will ask to one layout which leds should I display for the given time. And the concrete layout will answer. But Display sees just an abstraction of a layout, it does not know which layout is underneath.
This class read the light sensor.
This class read the rotary button. It keep track of the push and rotation. The information are then processed in the StateManager.
This class will:
- Keep track of the current state
- Change state if the button is pressed
- Take actions depending of the state when we rotate the button (for example if we are in the state CHANGE_BRIGHTNESS the action will be to change the brightness)
This class will communicate with the external clock to keep track of the time. If we change the time, it will write it to the external clock.
This class is in charge of powering on or off the led depending on the time, state, layout and ambiant light. This is the most complicated class of this project.
As previously said this is just an abstraction of a layout. It define which function the concrete layout must implements.
This class contains the layout. They define which leds should be on for a given time.
#Workflow
Like you can see in the main arduino loop each class are called one by one.

It's important that this loop goes as fast as possible. If one class takes too much time to execute, we may miss the rotation of the button. For example to be able to see 1 rotation per second of the rotary button, the loop has to be under 50ms (and one rotation per second is not very fast).