# coding: utf-8

import smbus
import time

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

TREX_SBW=0x0F
TREX_SBR=0xF0

#data_write = [0x0F,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]
data_write = [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]
data_write2 = [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]
data_write3 = [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]
while (1==1):

    try:
        bus.write_i2c_block_data(addr,0x0F,data_write) #RECULER
        time.sleep(1.0)
        message_recu = bus.read_byte(addr)
        #message_recu = bus.read_i2c_block_data(addr,0x00)        
        #print(message_recu[0])
        time.sleep(1.0)

        bus.write_i2c_block_data(addr,0x0F,data_write3) #STOP
        time.sleep(1.0)
        message_recu = bus.read_byte(addr)
        #message_recu = bus.read_i2c_block_data(addr,0x00)        
        #print(message_recu[0])
        time.sleep(1.0)

        bus.write_i2c_block_data(addr,0x0F,data_write2) #AVANCER
        time.sleep(1.0)
        message_recu = bus.read_byte(addr)
        #message_recu = bus.read_i2c_block_data(addr,0x00)        
        #print(message_recu[0])
        time.sleep(1.0)

        bus.write_i2c_block_data(addr,0x0F,data_write3) #STOP
        time.sleep(1.0)
        message_recu = bus.read_byte(addr)
        #message_recu = bus.read_i2c_block_data(addr,0x00)        
        #print(message_recu[0])
        time.sleep(1.0)


        print("fin boucle")
    except OSError as e:
        print(e)
