Tim's code for having two IRS sensors light Two LEDs
This is a progam that uses information from two Infra RED sensors tomake blink two LEDs
' {$STAMP BS2sx}
' {$PBASIC 2.5}
' -----[ Declarations ]----------------------------------------------------
adcBits VAR Byte 'declareing variable (ie adcbits is variable)
adcBits1 VAR Byte
' -----[ Initialization ]--------------------------------------------------
CS CON 0
CLK CON 1 'declaring pin constants (ie cs is always pin 0)
DataOutput CON 2
CS1 CON 12
CLK1 CON 11
DataOutput1 CON 10
' -----[ 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
HIGH CS1
LOW CS1
LOW CLK1
PULSOUT CLK1, 210
SHIFTIN DataOutput1,CLK1,MSBPOST,[adcBits1\8] 'declare value of adcbits
RETURN 'returns to main routine
led:
IF adcbits >= 024 THEN LOW 8
IF adcbits <= 023 THEN HIGH 8
IF adcbits1 >= 024 THEN LOW 9
IF adcbits1 <= 023 THEN HIGH 9
RETURN
Display1: 'opening and running debug window
DEBUG HOME
DEBUG "hex value: ", DEC3 adcBits, CR
DEBUG "hex value: ", DEC3 adcbits1,CR
'no person = steady 0, 1meter = between 2-50
RETURN
0 Comments:
Post a Comment
<< Home