1

I am trying to create something which uses Charlieplexing, and to use it, I need to be able to turn GPIO Pins to and from different states (Low, High and Input) from what I understand from this video: http://www.youtube.com/watch?v=ECXk95qYZu8.

To make a pin low (according to this), I would do:

final GpioController gpio = GpioFactory.getInstance();
GpioPinDigitalOutput myLed = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04,PinState.LOW);

or then myLed.low(); and likewise with High.

The problem is I don't think I can change the Pin's state to "Input". This says that I would have needed to create the variable as an GpioPinDigitalInput, not an GpioPinDigitalOutput.

Does anyone know how I can change a pin's state from High or Low to Input and vica-versa? Will "re-declaring" the variable work?

Thanks,

2

I used a GpioPinDigitalMultipurpose. More info can be found here.

One can then do:

// Provisions the pin.
GpioPinDigitalMultipurpose mypin = gpio.provisionDigitalMultipurposePin(RaspiPin.GPIO_04, PinMode.DIGITAL_INPUT);

// Sets it as an Output pin.
mypin.setMode(PinMode.DIGITAL_OUTPUT);

// Sets the state to "high".
mypin.high();

// Sets the state to "low".
mypin.low();

// Sets it as an Input pin.
mypin.setMode(PinMode.DIGITAL_INPUT);
  • 1
    why not use GpioPinDigitalMultipurpose for every in then? does it have some performance implications? – Laurynas Mališauskas Dec 26 '15 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.