You are on page 1of 3

Pseudo Code for servos.

c
FUNCTION: InitServos Takes a priority number, returns a boolean Set MyPriority to passed in parameter Run Servo12_Init with xxSSxxxx, post error if error happens Run Servo12_SetpulseWidth with HADES and OFF_POS, post error if error happens Run Servo12_SetpulseWidth with POSEIDON and OFF_POS, post error if error happens Set life to ON_POS Return True

FUNCTION: PostServos Takes event ThisEvent, returns boolean Run and return ES_PostToService with MyPriority and ThisEvent as parameters

FUNCTION: RunServos Takes and event ThisEvent, returns an event Initialize event ReturnEvent Set ReturnEvent event type to ES_NO_EVENT, assumes no errors Based on the state of ThisEvent event type: event type is ES_HADES_ON run ActivateHades event type is ES_HADES_SHOT run KillHades event type is ES_HADES_OFF run DeactivateHades event type is ES_POSEIDON_OFF run DeactivatePoseidon event type is ES_GAME_RESTART set seconds to 0 run DeactivateHades 1

run DeactivatePoseidon set life to ON_POS event type is ES_TIMEOUT if ThisEvent parameter is POSEIDON_TIMER run MovePoseidon Return ReturnEvent

Private Functions FUNCTION: ActivateHades Takes nothing, returns nothing Set pulse width for hades to ON_POS

FUNCTION: DeactivateHades Takes nothing, returns nothing Set pulse width for hades to OFF_POS

FUNCTION: MovePoseidon Takes nothing, returns nothing Set pulse width for Poseidon to ON_POS minus (seconds times 22) Increment seconds if seconds is less than or equal to 45 Initialize POSEIDON_TIMER to one second else Initialize event Poseidon_Timeout Set event type to ES_POSEIDON_TIMEOUT and parameter to 1 run PostGame with Poseidon_Timeout

FUNCTION: KillHades Takes nothing, returns nothing Initialize event ThisEvent Initialize event HadesDeadEvent 2

De-increment life by 5 if life set else set run set run is greater than 1200 pulse width for HADES to life ThisEvent event type to ES_HADES_DEAD PostGame with ThisEvent HadesDeadEvent event type to ES_SEND_REQUEST and parameter to 1 PostCommunication with HadesDeadEvent

FUNCTION: DeactivatePoseidon Takes nothing, returns nothing Set pulse width for POSEIDON to ON_POS Stop POSEIDON_TIMER

You might also like