Guys,
I think I need help with arrays.
Im working with the ADS1115 and have started to think about the Gain function, specifically how I can code it efficiently.
Essentially, the Gain is set based upon a maximum input voltage to the ADS1115, like this:
Gain Values (Set for maximum input voltage):
0 : 6.144V
1 : 4.096V
2 : 2.048V
3 : 1.024V
4 : 0.512V
5 : 0.256V
Currently my code simply states:
gain_value = 1
max_inp_volts = 4.096
…and then I use these values elsewhere in the code.
In my case though, the maximum input voltage is derived from another function that is dependant on another variable (water tank height). I would like to be able to say something like:
if water_tank_height = x, then gain_value = 4 and max_inp_volts = 0.512
I can fathom the logic to establish what the gain_value should be, but dont know how to efficiently and automatically call the correct gain_value and max_inp_volts.
I could do it in a series of if, then, else statements but that seems very inefficient.
Any thoughts guys?
Thanks
Jon