How to get value of voltage from ADS1015

30 views
Skip to first unread message

SylZi

unread,
Nov 14, 2017, 5:12:57 AM11/14/17
to Pi4J
I want to get the value of voltage from another class, but I don't know how to do it. I work on this example: https://github.com/Pi4J/pi4j/blob/master/pi4j-example/src/main/java/ADS1015GpioExample.java
In the line 105-121 there is anonymous inner class that printing the values of voltage etc.:

GpioPinListenerAnalog listener = new GpioPinListenerAnalog()
{
@Override
public void handleGpioPinAnalogValueChangeEvent(GpioPinAnalogValueChangeEvent event)
{
// RAW value
double value = event.getValue();
// percentage
double percent = ((value * 100) / ADS1015GpioProvider.ADS1015_RANGE_MAX_VALUE);
// approximate voltage ( *scaled based on PGA setting )
double voltage = gpioProvider.getProgrammableGainAmplifier(event.getPin()).getVoltage() * (percent/100);
// display output
System.out.println(" (" + event.getPin().getName() +") : VOLTS=" + df.format(voltage) + " | PERCENT=" + pdf.format(percent) + "% | RAW=" + value + " ");
}
};
I just want to sent value of voltage (get access to it) from another class to i.e. light diode when value of voltage will by to high or show this value on GUI. Its probably problem with my understanding of java, I tried to find solution, but without success.

SylZi

unread,
Nov 14, 2017, 1:53:53 PM11/14/17
to Pi4J
Reply all
Reply to author
Forward
0 new messages