include "modedefs.bas" SDO VAR PORTB.4 SCLK VAR PORTB.3 CS VAR PORTB.2 channel VAR BYTE brightness var byte(6) level var byte dataOut var word main: 'fade the LEDs up, one by one for channel = 0 to 5 for level = 0 to 255 gosub fadeChannel pause 3 next next 'fade the leds down for channel = 0 to 5 for level = 255 to 0 step 20 gosub fadeChannel pause 1 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