Closed onlinelei closed 3 years ago
Hi, no you can't have two GpioControllers at the same time. There is also no need for this. Am i right in thinking you want to access multiple pins at the same time? Then just get the singleton instance of the GpioController and then provision your pins:
GpioFactory.setExecutorServiceFactory(new SingleThreadGpioExecutorServiceFactory());
GpioFactory.setDefaultProvider(new RaspiGpioProvider(RaspiPinNumberingScheme.BROADCOM_PIN_NUMBERING));
GpioController controller = GpioFactory.getInstance();
Pin interruptPin = RaspiBcmPin.getPinByAddress(...);
GpioPinDigitalInput interruptGpioPin = gpioController.provisionDigitalInputPin(interruptPin, PinPullResistance.PULL_DOWN);
interruptGpioPin.addListener((GpioPinListenerDigital) this::handleInterrupt);
GpioPinDigitalOutput outputPin = gpioController.provisionDigitalOutputPin(...);
outputPin.setState(PinState.HIGH);
thanks
hello I have a question:
GpioController
is Singleton Pattern ? can I create two or more GpioController class operating pi I/O at the same time