You are on page 1of 3
FOLLOWER PIC PSEUDOCODE BranchSwitch InitSwitch(void): set switch pin as analog set switch pin as input configure ADC GetBranch(void): read ADC port default BranchType = error if (ADC val is within Branch_1 values): BranchType = Branch_1 if (ADC val is within Branch_2 values): BranchType = Branch_2 if (ADC val is within Branch_3 values): BranchType = Branch_3 Return BranchType ButtonService InitButtonService(void): set button pin as input configure this PIC as a follower in SPI read the button port to get initial value CheckButtonEvents(void): return value is false by default read the button port if (current button state != previous button state AND current button state is LOW): set retum value to true selected branch = GetBranch() ReturnEvent = {BUTTON_PRESS event, selected branch} post RetumEvent over SPI to leader if (rst time starting the game): post GAME_STARTED event to all services on this PIC set game started variable to true set previous button state to current button state retum ReturEvent LEDService InitLEDService (priority) set red LED pin as output set blue LED pin as output tum off red LED tum off blue LED RunLEDService(Event): switch on Event case GAME_START: tum off red LED tur off blue LED case FOUND_BEACON_B: tum on red LED tum off blue LED case FOUND_BEACON_C: tum off red LED tun on blue LED case GAME_END: turn off red LED turn off blue LED ServoService InitServoPWM (void): Tum off timer 3 On in idle mode Tum off gated mode Use PBCLK Prescale of 4 Clear T3 Set PR3 to 20 ms period Tum off OC1 Set servo pin as digital Set servo pin as input Use timer 3 as timebase 16 bit mode PWM non-fault mode Map OC1 to servo pin Set OCARS to “off” position Set OCAR to “off position” Tum on timer 3 Tum on OC1 InitServoService(void): InitServoPWM() InitButtonService() InitSwitches() RunServoService(Event): Switch on Event: Case INIT: Set servo to “off” position Case GAME_START: Set servo to “on” position Case GAME_END: Set servo to “off” position

You might also like