#! /usr/bin/env python3
#include <iostream>
#include <wiringPiI2C.h>
import time

from smbus import SMBus
import I2C_LCD_driver_24
import I2C_LCD_driver_27

lcd_24 = I2C_LCD_driver_24.lcd()
lcd_27 = I2C_LCD_driver_27.lcd()

ard_addr = bytearray([0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c])
number = bytearray([0, 0, 0, 0, 0, 0, 0, 0])

bus = SMBus(1) # indicates /dev/ic2-1
lcd_24 = I2C_LCD_driver_24.lcd()
lcd_27 = I2C_LCD_driver_27.lcd()
cnt = 0
while True:     
    while cnt < 8:
        number[cnt] = bus.read_byte(ard_addr[cnt])
        print("Arduino", ard_addr[cnt], "PR reporting", number[cnt])
        bus.write_byte(ard_addr[cnt], 0x1) # switch it on
        time.sleep(2)
        bus.write_byte(ard_addr[cnt], 0x0) # switch it on
        cnt +=1
        ## LCD 24
        # Arduino 4
        str_addr = "{}".format(ard_addr[0])
        str_num = "{}".format(number[0])
        lcd_24.lcd_display_string(str_addr, 1, 0)
        lcd_24.lcd_display_string(": ", 1, 1)
        lcd_24.lcd_display_string(str_num, 1, 2)
        
        # Arduino 5
        str_addr = "{}".format(ard_addr[1])
        str_num = "{}".format(number[1])
        lcd_24.lcd_display_string(str_addr , 1, 6)
        lcd_24.lcd_display_string(": ", 1, 7)
        lcd_24.lcd_display_string(str_num, 1, 8)
        
        # Arduino 6
        str_addr = "{}".format(ard_addr[2])
        str_num = "{}".format(number[2])
        lcd_24.lcd_display_string(str_addr , 1, 12)
        lcd_24.lcd_display_string(": ", 1, 13)
        lcd_24.lcd_display_string(str_num, 1, 14)
        
        # Arduino 7
        str_addr = "{}".format(ard_addr[3])
        str_num = "{}".format(number[3])
        lcd_24.lcd_display_string(str_addr, 2, 0)
        lcd_24.lcd_display_string(": ", 2, 1)
        lcd_24.lcd_display_string(str_num, 2, 2)
        
        # Arduino 8
        str_addr = "{}".format(ard_addr[4])
        str_num = "{}".format(number[4])
        lcd_24.lcd_display_string(str_addr , 2, 6)
        lcd_24.lcd_display_string(": ", 2, 7)
        lcd_24.lcd_display_string(str_num, 2, 8)
        
        # Arduino 9
        str_addr = "{}".format(ard_addr[5])
        str_num = "{}".format(number[5])
        lcd_24.lcd_display_string(str_addr , 2, 12)
        lcd_24.lcd_display_string(": ", 2, 14)
        lcd_24.lcd_display_string(str_num, 2, 15)
        
        # Arduino 10
        str_addr = "{}".format(ard_addr[6])
        str_num = "{}".format(number[6])
        lcd_24.lcd_display_string(str_addr, 3, 0)
        lcd_24.lcd_display_string(": ", 3, 2)
        lcd_24.lcd_display_string(str_num, 3, 3)
        
        # Arduino 11
        str_addr = "{}".format(ard_addr[7])
        str_num = "{}".format(number[7])
        lcd_24.lcd_display_string(str_addr , 3, 6)
        lcd_24.lcd_display_string(": ", 3, 8)
        lcd_24.lcd_display_string(str_num, 3, 9)
        
        ##LCD 27
        lcd_27.lcd_display_string("I2C Mini LCD", 1, 0)
        lcd_27.lcd_display_string("Address", 2, 0)
        lcd_27.lcd_display_string("0x27", 3, 0)
        
    cnt = 0
    print(" ")



