print("Hello, ESP32!")
#############################
###### IMPORT LIBRARIES ####
#############################

import machine
from utime import sleep

from lcd_api import LcdApi
from i2c_lcd import I2cLcd

import mpu6050

#############################
###### PIN CONFIGURATIONS ##
#############################

# Configure the pin as output
# Replace the x with SDA Pin x number here
sda=machine.Pin(21)

# Replace the y with SCL Pin y number here
scl=machine.Pin(22)

# i2c configuration
i2c = machine.SoftI2C(sda=sda, scl=scl, freq=10000)

# use i2c with devices
lcd = I2cLcd(i2c, 0x27, 2, 16)
mpu = mpu6050.MPU6050(i2c)


#############################
###### MAIN ROUTINE ########
#############################

def main():

    while True:
        # subroutine here
        sensor_data = mpu_i2c()
        lcd_i2c(sensor_data)


#############################
###### SUBROUTINES #########
#############################

def mpu_i2c():

    accel_data = mpu.read_accel_data()
    temp_data = mpu.read_temperature()

    print("acceleration_x: ", accel_data[0])
    print("acceleration_y: ", accel_data[1])
    print("acceleration_z: ", accel_data[2])
    print("temperature: ", temp_data)

    return accel_data, temp_data


def lcd_i2c(sensor_data):

    accel_data = sensor_data[0]
    temp_data = sensor_data[1]

    # select coordinate (column no. , row no.)
    lcd.move_to(0,0)
    display_text = "x: " + str("{:.2f}".format(accel_data[0]))
    lcd.putstr(display_text)

    # select coordinate (column no. , row no.)
    lcd.move_to(0,1)
    display_text = "y: " + str("{:.2f}".format(accel_data[1]))
    lcd.putstr(display_text)

    lcd.move_to(8,0)
    display_text = "z: " + str("{:.2f}".format(accel_data[1]))
    lcd.putstr(display_text)

    # select coordinate (column no. , row no.)
    lcd.move_to(8,1)
    display_text = "t: " + str("{:.1f}".format(temp_data))
    lcd.putstr(display_text)


#############################
###### EXECUTE MAIN ROUTINE
#############################

if __name__ == '__main__':
    main()
D0D1D2D3D4D5D6D7GNDLOGIC