'''''''''''''''''''''''''''''''''''''''''''''''''''''
'             SD21 controlling 21 servos                                        '
'              example in PicBasic PRO              '
'              By James Henderson 2009              '
'''''''''''''''''''''''''''''''''''''''''''''''''''''

define OSC 8                                        ' 8mhz oscillator
DEFINE I2C_SLOW 1                                   ' Set i2c to the standard speed
DEFINE I2C_HOLD 1                                   ' Enable the recieving i2c device to be able to pause communication

w0 var word                                         ' w0 Value servos are to move to
b0 VAR w0.byte0                                     ' b0 is the low byte of word w0
b1 VAR w0.byte1                                     ' b1 high byte of w0
i var byte                                          ' Byte used to select register to write to in loop

loop: 
    for w0 = 1000 to 1999 step 50                   ' This loop increments w0 to set servo position
        for i = 1 to 61 step 3                      ' Increment i by 3 each time to select first register of each servo
            i2cwrite PORTC.4,PORTC.3,$C2,i,[b0,b1]  ' Write low byte then high byte to address i
        next i
    next w0
    for w0 = 2000 to 1001 step -50                  ' This loop increments w0 to set servo position
         for i = 1 to 61 step 3                     ' Increment i by 3 each time to select first register of each servo
            i2cwrite PORTC.4,PORTC.3,$C2,i,[b0,b1]  ' Write low byte then high byte to address i
        next i
    next w0
Goto loop
