;Changes from Ver 1.0: ;Increased some sensors' sensitivity from 150 to 300 ; ;added wait in powerup sequence to make sure right values are set ; ;commented out sensor 9-12 initialization in powerup as it's not needed ; ;added wait 5 after conditional statements so that dupe values aren't sent to powerup ;On powerup, get initial (background) values of sensors Write porta-ddr $0F ;set A0 A1 A2 A3 as inputs Write portb-ddr $00 ;set all of portb as outputs write portb $7F ;set only B7 as low setaO (read-ad 0) ;read sensor a setbO (read-ad 1) setcO (read-ad 2) setdO (read-ad 3) write portb $BF ;set only B6 as low wait 5 ;pause to make sure values get set seteO (read-ad 0) ;read sensor e setfO (read-ad 1) setgO (read-ad 2) sethO (read-ad 3) end to startup Write porta-ddr $0F ;set A0 A1 A2 A3 as inputs Write portb-ddr $00 ;set all of portb as outputs loop[ ;Comment out loop for debug - otherwise loop forever read-array1 ;get values for first 4 sensors checka ;compare values checkb checkc checkd wait 1 ;The wait keeps it from making the same sounds over and over read-array2 ;get values for next 4 sensors checke ;compare values checkf checkg checkh wait 1 ] end global [aO bO cO dO eO fO gO hO iO jO kO lO] ;background variables global [a b c d e f g h i j k l] ;current variables to read-array1 ;Get current values write portb $7F seta (read-ad 0) setb (read-ad 1) setc (read-ad 2) setd (read-ad 3) end to read-array2 ;Get current values write portb $BF sete (read-ad 0) setf (read-ad 1) setg (read-ad 2) seth (read-ad 3) end to checka ;Compare current-background values if ( a > aO ) [ if (a > ( aO + 300 )) ;If at least 150 bigger than background: [ ;Sensor sees less light send 00 ;Send '00' to Pd wait 5 ;wait so no dupe values ] ] if ( a < aO ) [ if ( a < ( aO - 300 )) ;If at least 150 smaller than background: [ ;Sensor sees more light send 01 ;send '01' to Pd wait 5 ;wait so that dupe values ] ] end to checkb if ( b > bO ) [ if (b > ( bO + 100 )) [ ;Sensor sees less light send 10 wait 5 ;wait so no dupe values not sent ] ] if ( b < bO ) [ if ( b < ( bO - 100 )) [ ;Sensor sees more light send 11 wait 5 ;wait so no dupe values sent ] ] end to checkc if ( c > cO ) [ if (c > ( cO + 300 )) [ ;Sensor sees less light send 20 wait 5 ;wait so no dupe values ] ] if ( c < cO ) [ if ( c < ( cO - 150 )) [ ;Sensor sees more light send 21 wait 5 ;wait so no dupe sent ] ] end to checkd if ( d > dO ) [ if (d > ( dO + 300 )) [ ;Sensor sees less light send 30 wait 5 ;wait so no dupe value ] ] if ( d < dO ) [ if ( d < ( dO - 150 )) [ ;Sensor sees more light send 31 wait 5 ;wait so no dupe ] ] end to checke if ( e > eO ) [ if (e > ( eO + 75 )) [ ;Sensor sees less light send 40 wait 5 ] ] if ( e < eO ) [ if ( e < ( eO - 300 )) [ ;Sensor sees more light send 41 wait 5 ] ] end to checkf if ( f > fO ) [ if (f > ( fO + 150 )) [ ;Sensor sees less light send 50 wait 5 ] ] if ( f < fO ) [ if ( f < ( fO - 300 )) [ ;Sensor sees more light send 51 wait 5 ] ] end to checkg if ( g > gO ) [ if (g > ( gO + 150 )) [ ;Sensor sees less light send 60 wait 5 ] ] if ( g < gO ) [ if ( g < ( gO - 150 )) [ ;Sensor sees more light send 61 wait 5 ] ] end to checkh if ( h > hO ) [ if (h > ( hO + 150 )) [ ;Sensor sees less light send 70 wait 5 ] ] if ( h < hO ) [ if ( h < ( hO - 300 )) [ ;Sensor sees more light send 71 wait 5 ] ] end