package rc_meassure; import com.pi4j.io.gpio.GpioController; import com.pi4j.io.gpio.GpioFactory; import com.pi4j.io.gpio.GpioPinDigitalInput; import com.pi4j.io.gpio.GpioPinDigitalOutput; import com.pi4j.io.gpio.Pin; import com.pi4j.io.gpio.PinState; import com.pi4j.io.gpio.RaspiPin; import static java.lang.Math.pow; import java.util.concurrent.TimeUnit; /** * * In einer echten Java Anwendung würde man das nicht so machen, das dient wirklich nur als Beispiel. */ public class RC_meassure { /** * @param args the command line arguments */ static Pin rcPin = RaspiPin.GPIO_00; static final int r = 100000; static final float c = (float) (100 * pow(10, -9)); /** * Vih = 0.625*Vdd * http://www.farnell.com/datasheets/1835725.pdf */ static final float vih = (float) 2.976473; public static void main(String[] args) throws InterruptedException { GpioController gpio = GpioFactory.getInstance(); gpio.unexportAll(); final GpioPinDigitalOutput outPin = gpio.provisionDigitalOutputPin(rcPin); outPin.setShutdownOptions(true, PinState.LOW); outPin.low(); //Entlade Kondensator; TimeUnit.SECONDS.sleep(1); //gpio.shutdown(); gpio.unprovisionPin(outPin); long startTime = System.nanoTime(); final GpioPinDigitalInput inPin = gpio.provisionDigitalInputPin(rcPin); while(inPin.isLow()){ //warte } long estimatedTime = System.nanoTime() - startTime; gpio.unprovisionPin(inPin); System.out.println(estimatedTime); System.out.println("Voltage: " + meassureRCVoltage(estimatedTime, r, c, vih)); } static float meassureRCVoltage(long t, float r, float c, float vih_voltage){ float vbat = (vih_voltage * c * r) /((float)(t * pow(10, -9))); return vbat; } }