import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.GpioPin;
import com.pi4j.io.gpio.Pin;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;
public class Led
{
// instance variables - replace the example below with your own
private GpioPinDigitalOutput pin;
/**
* Constructor for objects of class Led
*/
public Led(Pin pinId)
{
if(pinId == null){
pinId = RaspiPin.GPIO_01;
}
GpioController gpio = GpioFactory.getInstance();
try{ // create gpio controller
pin = gpio.provisionDigitalOutputPin(pinId);
} catch(Exception e){
// sollte er noch offen sein schliess mal alles und versuche es nochmal
gpio.shutdown();
gpio.unprovisionPin(gpio.getProvisionedPins().toArray(new GpioPin[]{}));
gpio = GpioFactory.getInstance();
pin = gpio.provisionDigitalOutputPin(pinId);
}
}
void on(){
pin.high();
}
void off(){
pin.low();
}
void toggle(){
if(pin.isHigh()){
pin.low();
}else {
pin.high();
}
}
public void close(){
GpioController gpio = GpioFactory.getInstance();
gpio.unprovisionPin(gpio.getProvisionedPins().toArray(new GpioPin[]{pin}));
}
}