# coding: utf-8

import smbus
import time

bus=smbus.SMBus(1)
addr=0x07

TREX_SBW=0x0F
TREX_SBR=0xF0

reculer = [0x02,0x00,0xFF,0x00,0x00,0xFF,0x00,0x05,0xDC,0x05,0xDC,0x05,0xDC,0x05,0xDC,0x00,0x00,0x00,0x00,0x32,0x00,0x32,0x02,0x23,0x07,0x00]    #RECULER
avancer = [0x02,0xFF,0x01,0x00,0xFF,0x01,0x00,0x05,0xDC,0x05,0xDC,0x05,0xDC,0x05,0xDC,0x00,0x00,0x00,0x00,0x32,0x00,0x32,0x02,0x23,0x07,0x00]   #AVANCER
stop = [0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0xDC,0x05,0xDC,0x05,0xDC,0x05,0xDC,0x00,0x00,0x00,0x00,0x32,0x00,0x32,0x02,0x23,0x07,0x00]   #STOP
gauche = [0x02,0x00,0xFF,0x00,0x00,0x00,0x00,0x05,0xDC,0x05,0xDC,0x05,0xDC,0x05,0xDC,0x00,0x00,0x00,0x00,0x32,0x00,0x32,0x02,0x23,0x07,0x00]   #GAUCHE
droite = [0x02,0x00,0x00,0x00,0x00,0xFF,0x00,0x05,0xDC,0x05,0xDC,0x05,0xDC,0x05,0xDC,0x00,0x00,0x00,0x00,0x32,0x00,0x32,0x02,0x23,0x07,0x00]   #DROITE

while (1==1):

    try:
        bus.write_i2c_block_data(addr,0x0F,reculer) #RECULER
        time.sleep(1.0)
        message_recu = bus.read_byte(addr)
        time.sleep(1.0)

        bus.write_i2c_block_data(addr,0x0F,stop) #STOP
        time.sleep(1.0)
        message_recu = bus.read_byte(addr)
        time.sleep(1.0)

        bus.write_i2c_block_data(addr,0x0F,avancer) #AVANCER
        time.sleep(1.0)
        message_recu = bus.read_byte(addr)
        time.sleep(1.0)

        bus.write_i2c_block_data(addr,0x0F,stop) #STOP
        time.sleep(1.0)
        message_recu = bus.read_byte(addr)
        time.sleep(1.0)

        bus.write_i2c_block_data(addr,0x0F,gauche) #GAUCHE
        time.sleep(1.0)
        message_recu = bus.read_byte(addr)
        time.sleep(1.0)

        bus.write_i2c_block_data(addr,0x0F,stop) #STOP
        time.sleep(1.0)
        message_recu = bus.read_byte(addr)
        time.sleep(1.0)

        bus.write_i2c_block_data(addr,0x0F,droite) #DROITE
        time.sleep(1.0)
        message_recu = bus.read_byte(addr)
        time.sleep(1.0)

        bus.write_i2c_block_data(addr,0x0F,stop) #STOP
        time.sleep(1.0)
        message_recu = bus.read_byte(addr)
        time.sleep(1.0)
        
        print("fin boucle")
    except OSError as e:
        print(e)
