Timothy's ANDY




ANDY'S CODE FOR SOUND
' {$STAMP BS2sx} 'refer to image 12
' -----[ Declarations ]----------------------------------------------------
adcBits VAR BYTE 'declareing variable (ie adcbits is variable)
i VAR BYTE
f VAR WORD
' -----[ Initialization ]--------------------------------------------------
CS CON 0
CLK CON 1 'declaring pin constants (ie cs is always pin 0)
DataOutput CON 2
C CON 2092 'declaring note tones
D CON 2348
E CON 2636
G CON 3136
R CON 8
' -----[ Main Routine ]----------------------------------------------------
DO
GOSUB ADC_Data ' gets the data
GOSUB mary 'related the amp/speaker 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
mary:
IF adcbits >= 024 THEN lamb 'tells system to activate if someone in front of sensor
RETURN
lamb: 'tells system what notes to play
FOR i = 0 TO 28
LOOKUP i,[E,D,C,D,E,E,E,R,D,D,D,R,E,G,G,R,E,D,C,D,E,E,E,E,D,D,E,D,C],f
FREQOUT 8,1000,f,(f-8) MAX 32768
RETURN
Display1: 'opening and running debug window
DEBUG HOME
DEBUG "hex value: ", DEC3 adcBits, CR
'no person = steady 0, 1meter = between 2-50
RETURN
0 Comments:
Post a Comment
<< Home