I am trying to develop a function using OOPs. But I am getting following error. The function basically for the Raspberry Pi. It has been working fine when I use it without any OOPs structure.
Code:
import Adafruit_ADS1x15 as ada_adc
class read_raspberrypi_analog_input:
## Default level
# The following is executed when self is called
def __init__():
# call an instance of ADS1015 if it is used for readin analog input signal
self.adc = ada_adc
def through_ads1015(self, adc_gain = 1, r1 = 1, r2 = 0):
adc = self.adc.ADS1015()
GAIN = adc_gain
# read the value at the board input analog pin A0
a0_level = adc.read_adc(0, gain=GAIN)
print(a0_level)
a0_analog = a0_level*(4.096/2047)
print(a0_analog)
# actual sensor input voltage
r1 = r1
r2 = r2
a0_sensor = a0_analog *(r1+r2)/r1
print(a0_sensor)
Call the class and method:
read_raspberrypi_analog_input.through_ads1015(adc_gain = 1, r1 = 5.1, r2 = 3)
Present output:
read_raspberrypi_analog_input.through_ads1015(adc_gain = 1, r1 = 5.1, r2 = 3)
TypeError: through_ads1015() missing 1 required positional argument: 'self'