Timothy's SILHOUETTE project


Code for Lights
' {$STAMP BS2sx} 'refer to imeges 5&6
' {$PBASIC 2.5}
' -----[ Declarations ]----------------------------------------------------
adcBits VAR BYTE 'declareing variable (ie adcbits is variable)
' -----[ Initialization ]--------------------------------------------------
CS CON 0
CLK CON 1 'declaring pin constants (ie cs is always pin 0)
DataOutput CON 2
' -----[ Main Routine ]----------------------------------------------------
DO
GOSUB ADC_Data ' gets the data
GOSUB led 'related the led to sensor
GOSUB Display1 'go to subroutine to show the numbers
LOOP
' -----[ Subroutines ]-----------------------------------------------------
ADC_Data: 'runs the commands for the ADC
HIGH CS
LOW CS
LOW CLK
PULSOUT CLK, 210
SHIFTIN DataOutput,CLK,MSBPOST,[adcBits\8] 'declare value of adcbits
RETURN 'returns to main routine
led:
IF adcbits >= 024 THEN LOW 8 'tells led to turn on when there is no one
IF adcbits <= 023 THEN HIGH 8 'in fron of the sensor and off when there is
RETURN
Display1: 'opening and running debug window
DEBUG HOME
DEBUG "hex value: ", DEC3 adcBits, CR
'no person = steady 0, 1meter = between 2-50
RETURN




