You are on page 1of 4

OptoSensorCheck.

c
Define threshold values for the opto sensors and index values for each
of the optos in the opto array
Module level variable: optoInput array with 5 uint32_t elements

InitOptoSensor
Initialize each opto sensor by setting the ANSEL and TRIS bits for the
pins to 1
Call ADC_ConfigAutoScan function to complete the set-up and map the
array to the assigned pins
End of InitOptoSensor

CheckOptoSensor
Initialize and set ReturnVal to false
Call ADC_MultiRead function, passing it the optoInput array to
population with the sensor values
Return ReturnVal
End of CheckOptoSensor

CheckInnerOptos
Returns true if any of the inner (center, left, right) opto sensors
are on the tape and false otherwise
End of CheckInnerOptos

CheckCenter
Returns true if the center opto sensor is on the tape and false
otherwise
End of CheckCenter

CheckLeft
Returns true if the left opto sensor is on the tape and false
otherwise
End of CheckLeft

CheckRight
Returns true if the right opto sensor is on the tape and false
otherwise
End of CheckRight

CheckFront
Returns true if the front opto sensor is on the tape and false
otherwise
End of CheckFront

CheckBack
Returns true if the back opto sensor is on the tape and false
otherwise
End of CheckBack

ButtonEventCheck.c
Define the ports to read from each of the 4 buttons
Define variables for each of the button colors that correspond to a
branch (RED, GREEN, BLUE)
Module level variables: LastButtonState, LastRedButtonState,
LastGreenButtonState, LastBlueButtonState, LastChosenBranch,
buttonMode, timerButton

InitButtonStatus
Initialize the port lines to receive button data
Set the last button state variables to the values on the corresponding
PIC pins
Set the LastChosenBranch variable to RED
Set buttonMode to 0 and timerButton to 1
End of InitButtonStatus

CheckButton
Read in yellow button data
ButtonState
If the current button state and timerButton both equal 1
Post an ES_START event to the PropellerBot service
Reset timerButton to 0
Set ReturnVal to true
Update LastButtonState to current button state
Return true if button event was posted, otherwise return false
End of CheckButton

CheckRedButton
Read in the data from the red button pin

If the current button state is 1


If buttonMode is 0
If the LastChosenBranch is RED
Post a SAME_BRANCH event to PropellerBot Service
with a parameter of 1
Else, post a DIFFERENT_BRANCH event to PropellerBot
Service with a parameter of 1
Else if buttonMode is 1
Post a TURN_LITTLE_LEFT event to PropellerBot Service
Set ReturnVal to true
Update LastRedButtonState to current button state
Return true if an event was posted, otherwise return false
End of CheckRedButton

CheckGreenButton
Read in the data from the green button pin
onState
If the current button state is 1
If buttonMode is 0
If the LastChosenBranch is GREEN
Post a SAME_BRANCH event to PropellerBot Service
with a parameter of 2
Else, post a DIFFERENT_BRANCH event to PropellerBot
Service with a parameter of 2
Else if buttonMode is 1
Post a LITTLE_FORWARD event to PropellerBot Service
Set ReturnVal to true
Update LastGreenButtonState to current button state
Return true if an event was posted, otherwise return false
End of CheckGreenButton

CheckBlueButton
Read in the data from the blue button pin

If the current button state is 1


If buttonMode is 0
If the LastChosenBranch is BLUE
Post a SAME_BRANCH event to PropellerBot Service
with a parameter of 3
Else, post a DIFFERENT_BRANCH event to PropellerBot
Service with a parameter of 3
Else if buttonMode is 1
Post a TURN_LITTLE_RIGHT event to PropellerBot Service
Set ReturnVal to true
Update LastBLueButtonState to current button state
Return true if an event was posted, otherwise return false
End of CheckBlueButton

SwitchButtonMode
If buttonMode is 0
Set buttonMode to 1
Send command to follower to turn on manual mode LED
Else, set buttonMode to 0 and send command to follower to turn off
manual mode LED
End of SwitchButtonMode

buttonTimer
If timerButton is 0, set timerButton to 1
End of buttonTimer
LimitSwitchEventCheck.c
Define port for limit switch pin
Module level variables: LastLimitState

InitLimitSwitchStatus
Initialize the port line to receive limit swithc data
Set LastLimitState to the value on pin A2
End of InitLimitSwitchStatus

CheckLimitSwitch
Set ReturnVal to false
Read in input from limit switch pin
If the current limit switch state does not equal the last limit switch
state
If the current limit switch state is 1
Post a LIMIT_SWITCH_HIT even to PropellerBot service
Set ReturnVal to true
Update LastLimitState to current limit state
Return true if limit event was posted, otherwise return false
End of CheckLimitSwitch

You might also like