Vibration Control Pseudo Code
The Vibration Control service interprets the analog input from the potentiometer and contains helper functions to turn vibration on and off
InitVibrationControl
Initialize the PWM pins
Initialize the Pot as an Analog Input
Post ES_INIT event
RunVibrationControl
If ThisEvent is ES_INIT
Turn vibration on
Set the last value of the pot to the current value
CheckForTiltChange
Find the current value of the pot
if CurrentValuePot is different from LastValuePot by the defined tolerance
Map the Pot Value to the Duty Cylce
Set motor speed using the new duty cycle
Set the last value to the current value
MapPotValToDuty
Find the relative offset from level (of the current pot value)
Find the percentage change to map the duty cycle
Initialize the PWM pins
Initialize the Pot as an Analog Input
Post ES_INIT event
RunVibrationControl
If ThisEvent is ES_INIT
Turn vibration on
Set the last value of the pot to the current value
CheckForTiltChange
Find the current value of the pot
if CurrentValuePot is different from LastValuePot by the defined tolerance
Map the Pot Value to the Duty Cylce
Set motor speed using the new duty cycle
Set the last value to the current value
MapPotValToDuty
Find the relative offset from level (of the current pot value)
Find the percentage change to map the duty cycle