Try that for grins...Code:disable blue var byte:green var byte:red var byte:greenled var gpio.0 redled var gpio.1:ansel=$68:greenled var gpio.0:trisio=0:temp var word pwmcount var byte:adread var word:adcon=$8d:goto mainloop on interrupt goto inthandle inthandle: if intcon.2 = 1 then 'tmr 0 overflow fired off intcon.2 = 0 : pwmcount = pwmcount + 1 : if pwmcount = 0 then gpio = 0 if green > pwmcount then greenled = 1 if blue > pwmcount then blue = 1 if red > pwmcount then red = 1 endif if pir1.6 = 1 then 'a/d convert int fired off pir1.6=0:adread.highbyte=adresh:adread.lowbyte=adres if adread < 327 then adread = 0 'if less than minimum zero it if adread > 460 then adread = 133 'if more than max, max it out adread = adread - 327 'range of 133 (.0048828125 volts/bit) adread = adread * 30 'scale it up to reach 12 usable bits red=0:red.7=adread.11:red.6=adread.10:red.5=adread.9:red.4=adread.8 blue=0:blue.7=adread.7:blue.6=adread.6:blue.5=adread.5:blue.4=adread.4 green=0:green.7=adread.3:green.6=adread.2:green.5=adread.1:green.4=adread.0 endif resume enable mainloop: @ nop if adcon.1 = 0 then adcon.1 = 1 @ nop goto waitforad End
The LEDs should follow the voltage from 0 to 5v. If it actually works (I haven't tried it), you should be able to scale adread when it's read according to what you want to do. I just threw this together. Anything less than 1.6v, LEDs are dark, more than 2.25v LEDs are full bright, anything in between, the number gets converted to a 12bit value, high 4 bits to red, mid 4 bits to green, low 4 bits to blue.


						
					
				
				
				
				
			

Bookmarks