' PicBasic Pro program to read the signal ' from an IR photodiode, send it to serial out, ' and light up an LED when a signal is found. ' Connect analog input to channel-0 (RA0) ' Define ADCIN parameters DEFINE ADC_BITS 10 ' Set number of bits in result DEFINE ADC_CLOCK 3 ' Set clock source (3=rc) DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS ADCvar VAR WORD ' Create variable to store result TRISA = %11111111 ' Set PORTA to all input ADCON1 = %10000010 ' Set PORTA analog and right justify result Pause 500 ' Wait .5 second main: ADCIN 0, ADCvar ' Read channel 0 to adval serout2 PORTD.7, 16468, [DEC ADCvar, 13, 10] ' print it to serial out, ' with linefeed and carriage return (10, 13) if ADCvar > 0 then ' we have detected an IR signal high portd.1 ' light up the first segment of the bar LED graph endif if ADCvar > 50 then ' if the signal is stronger, light up another bar high portd.0 endif if ADCvar > 100 then ' if the signal is stronger still, light another high portc.3 endif if ADCvar > 150 then 'etc high portc.2 endif if ADCvar > 200 then 'etc high portc.1 endif if ADCvar > 250 then 'etc high portc.0 endif if ADCvar = 0 then 'start turning leds off when the signal dies low portd.1 endif if ADCvar < 50 then low portd.0 endif if ADCvar < 100 then low portc.3 endif if ADCvar < 150 then low portc.2 endif if ADCvar < 200 then low portc.1 endif if ADCvar < 250 then low portc.0