'******************************************************** ' ir_analysis.bas ' Program to analize output from infrared sensor modules ' PicBasic Pro Compiler '******************************************************** trisa = %11111111 ' set porta to inputs trisb = %00001100 ' set portb pins 2 & 3 to inputs temp var byte ' initialize variables ir_left var byte ir_right var byte l_count var byte r_count var byte l_threshold var byte r_threshold var byte num_samples var byte num_samples = 30 ' number of samples taken per i.r. module l_threshold = 15 ' noise floor threshold for left detector r_threshold = 15 ' noise floor threshold for right detector start: gosub infrared ' get sensor values from infrared subroutine if ir_left = 1 then ' if left detector senses an object then high portb.1 ' turn on left LED sound portb.4,[130,1,90,2,100,1,110,2] ' output left insect noise else low portb.1 endif if ir_right = 1 then ' if right detector senses an object then high portb.0 ' turn on right LED sound portb.4,[140,1,120,2,110,1,100,2] ' output right insect noise else low portb.0 endif goto start infrared: l_count = 0 r_count = 0 ir_left = 0 ir_right = 0 for temp = 1 to num_samples ' take 30 samples per detector if portb.2 = 0 then ' if left module senses an object l_count = l_count + 1 ' increase the left count endif if portb.3 = 0 then ' if left module senses an object r_count = r_count + 1 ' increase the right count endif next if l_count >= l_threshold then ' if left count is greater than the threshold ir_left = 1 ' then an object was sensed with left detector endif if r_count >= r_threshold then ' if right count is greater than the threshold ir_right = 1 ' then an object was sensed with right detector endif return ' return to main program end