ACtive State machine
The active state machine handles all user interactions with Baby Yoda. The service receives events from the three event checkers that allow for input from the user, then sends events to the corresponding services to handle the responses. The active state machine also keeps track of time and shuts off Baby Yoda after 30 seconds of inactivity or if the user does not make it to the defined relaxation state within 60 seconds. The service has an additional timer to keep track of and post an event to respond to the passage of time in one second increments. The active state machine receives progress events from the ServoService, VibrationService, and PrintService, and sends progress events to the LightSaberService.
light saber (progress) service
The LightSaberService keeps track of the user's progress towards the defined relaxation state. Each time a progress event is posted to the service, it sets the next LED pin high, lighting up another LED in Baby Yoda's light saber. When all six LEDs have been lit, the LightSaberService posts an event to ActiveSM to enter the Nirvana state and celebrate the user's newfound relaxation. The LightSaberService also responds to a light show event by lighting up the six LEDs in different patterns.
Servo service
The servo service handles all three servos in the project: two ear servos (one for each ear) and one servo for both eyes. Note that the ear servos are controlled by the same PWM signal. This service responds to events to open and close the eyes as well as to lower the eyes by a small increment to show the passage of time (after 60 seconds, Baby Yoda's eyes lids fully lower). The service also responds to events to raise and lower the ears. Additionally, the service responds to potentiometer turned events, mapping the potentiometer value posted as an event parameter to a pulse width that will set the position of the ear servos between the ears up and ears down positions depending on the potentiometer value. If the potentiometer is turned far enough then turned back to its initial position, the servo service posts a progress made event to ActiveSM. The servo service also responds to an event to wiggle the ears, moving the ears up and down during the Welcoming and NirvanaState states in ActiveSM.
Print service
The print service stores the messages that will appear on Baby Yoda's LED display during user interaction. Each time a send welcome or send character event (depending on the state of the service) is received, the service will post a new key event to the LED service and pass the next element of the message to the LED service to display on the LED matrix. When in the WaitingForBreath state, the print service also keeps track of when the affirmation message has been complete and posts progress made events to ActiveSM.
vibration service
The vibration service turns the vibration motors on and off based off events posted to it from the ActiveSM service. If the motors are activated for at least two seconds, the service posts a progress made event to ActiveSM.
LED (Display) service
The LED service receives events containing characters, adds the characters to the display buffer, then updates each row of the LED matrix to display the characters on the screen.