include "modedefs.bas" channel VAR BYTE brightness var byte(6) level var byte dataOut var word qprox var portb.1 SDO VAR PORTB.4 SCLK VAR PORTB.3 CS VAR PORTB.2 input qprox output portb.5 main: 'fade the LEDs up, one by one for channel = 0 to 5 for level = 0 to 255 gosub fadeChannel pause 3 gosub checkQPROX next next 'fade the leds down for channel = 0 to 5 for level = 255 to 0 step 20 gosub fadeChannel pause 1 gosub checkQPROX next next goto main fadeChannel: brightness(channel) = level 'take chip select low to activate ad5206 low cs 'put channel number in first byte to shift out dataOut.highbyte = channel 'put brightness in second byte to shift out dataout.lowbyte = brightness(channel) 'shift out 11 bits from dataOut shiftout sdo, sclk, MSBFIRST, [dataOut\11] high cs return checkQPROX: if portb.1=1 then high portb.5 else low portb.5 endif return