def calibrate_scale(hx):
    input('Put known weight on the scale and then press Enter')
    reading = hx.get_data_mean()
    if reading:
        print('Mean value from HX711 subtracted by offset:', reading)
        user_input = input('Write how many grams it was and press Enter: ')
        try:
            weight = float(user_input)
            print(weight, 'grams')
        except ValueError:
            print('Expected integer or float and I have got:', user_input)
        ratio = (reading / weight)
        hx.set_scale_ratio(ratio)
        print('Ratio is set.')
    else:
        raise ValueError('Cannot calculate mean value.')
def calibrate_scale(hx):
    input('Put known weight on the scale and then press Enter')
    reading = hx.get_data_mean()
    if reading:
        print('Mean value from HX711 subtracted by offset:', reading)
        user_input = input('Write how many grams it was and press Enter: ')
        try:
            weight = float(user_input)
            print(weight, 'grams')
        except ValueError:
            print('Expected integer or float and I have got:', user_input)
        ratio = (reading / weight)
        hx.set_scale_ratio(ratio)
        print('Ratio is set.')
    else:
        raise ValueError('Cannot calculate mean value.')