'''''''''''''''''''''''''''''''''''''''''''''''''''''
'                      MD22 i2c                     '
'                all mode switches on               '
'              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

i var byte                                          ' Byte that sets speed of motor
w var byte                                          ' Byte that selects motor 1 or 2

loop:
    i2cwrite PORTC.4,PORTC.3,$B0,0,[0]              ' set to mode 0(default mode) drive motors seperatly
    for w = 1 to 2
        for i = 128 to 255 step 5
            i2cwrite PORTC.4,PORTC.3,$B0,w,[i]      ' increase speed of motor w speed to i
            pause 100                               
        next i
    next w
    
    i2cwrite PORTC.4,PORTC.3,$B0,0,[2]              ' Change to mode 2, drive both motors at same time
    
    for i = 128 to 255 step 5
        i2cwrite PORTC.4,PORTC.3,$B0,1,[i]          ' increase speed of both motors by i
        pause 100                                   
    next i
    for i = 255 to 128 step -5
        i2cwrite PORTC.4,PORTC.3,$B0,1,[i]          ' decrease speed of both motors by i
        pause 100                                   
    next i
goto loop
    

