本文整理匯總了Java中com.pi4j.io.gpio.GpioFactory類的典型用法代碼示例。如果您正苦於以下問題:Java GpioFactory類的具體用法?Java GpioFactory怎麽用?Java GpioFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GpioFactory類屬於com.pi4j.io.gpio包,在下文中一共展示了GpioFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: provisionPwmOutputs
import com.pi4j.io.gpio.GpioFactory; //導入依賴的package包/類
private static GpioPinPwmOutput[] provisionPwmOutputs(final PCA9685GpioProvider gpioProvider) {
GpioController gpio = GpioFactory.getInstance();
GpioPinPwmOutput myOutputs[] = {
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_00, "Pulse 00"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_01, "Pulse 01"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_02, "Pulse 02"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_03, "Pulse 03"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_04, "Pulse 04"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_05, "Pulse 05"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_06, "Pulse 06"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_07, "Pulse 07"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_08, "Pulse 08"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_09, "Pulse 09"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_10, "Always ON"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_11, "Always OFF"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_12, "Servo pulse MIN"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_13, "Servo pulse NEUTRAL"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_14, "Servo pulse MAX"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_15, "not used")};
return myOutputs;
}
示例2: provisionPwmOutputs
import com.pi4j.io.gpio.GpioFactory; //導入依賴的package包/類
private GpioPinPwmOutput[] provisionPwmOutputs(final PCA9685GpioProvider gpioProvider) {
GpioController gpio = GpioFactory.getInstance();
GpioPinPwmOutput myOutputs[] = {
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_00, "Servo 00"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_01, "not used"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_02, "not used"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_03, "not used"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_04, "not used"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_05, "not used"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_06, "not used"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_07, "not used"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_08, "not used"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_09, "not used"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_10, "not used"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_11, "not used"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_12, "not used"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_13, "not used"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_14, "not used"),
gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_15, "not used")};
return myOutputs;
}
示例3: main
import com.pi4j.io.gpio.GpioFactory; //導入依賴的package包/類
public static void main(String[] args) {
System.out.println("<--Pi4J--> GPIO Frequency Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// provision gpio pin #01 as an output pin and turn on
final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, PinState.LOW);
// continuous loop
while(true) {
pin.setState(true);
pin.setState(false);
}
// stop all GPIO activity/threads by shutting down the GPIO controller
// (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
// gpio.shutdown(); <--- implement this method call if you wish to terminate the Pi4J GPIO controller
}
示例4: PumpDiagGuiSingle
import com.pi4j.io.gpio.GpioFactory; //導入依賴的package包/類
/**
* Creates new form MainWindow
*
* @throws com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException
* @throws java.io.IOException
*/
public PumpDiagGuiSingle() throws I2CFactory.UnsupportedBusNumberException, IOException, IOException, InterruptedException {
gpio = GpioFactory.getInstance(); // Singleton instance
mcpProvider = new MCP23017GpioProvider(I2CBus.BUS_1, 0x23);
// Provision direction control pins as outputs
System.out.println("Provisioning direction pin");
dir = gpio.provisionDigitalOutputPin(mcpProvider, MCP23017Pin.GPIO_A7, "Direction", PinState.LOW);
// Provision step control pins as outputs
System.out.println("Provisioning step pin");
step = gpio.provisionDigitalOutputPin(mcpProvider, MCP23017Pin.GPIO_A6, "Step", PinState.LOW);
// Provision enable pins as outputs.
// Note that the pin state "high" means the pump is disabled;
// the enable pump on the chip is inverted.
System.out.println("Provisioning enable pin");
enable = gpio.provisionDigitalOutputPin(mcpProvider, MCP23017Pin.GPIO_A5, "~Enable", PinState.HIGH);
}
示例5: GpioManager
import com.pi4j.io.gpio.GpioFactory; //導入依賴的package包/類
public GpioManager() {
this.gpio = GpioFactory.getInstance();
this.assignedPins = new ArrayList<NamedPin>();
this.availablePins = new ArrayList<NamedPin>();
// The following must be done in this long form
// due to the lack of pattern in true GPIO
// pin numbering.
availablePins.add(new NamedPin("GPIO 4", RaspiPin.GPIO_07, null));
availablePins.add(new NamedPin("GPIO 5", RaspiPin.GPIO_20, null));
availablePins.add(new NamedPin("GPIO 6", RaspiPin.GPIO_22, null));
availablePins.add(new NamedPin("GPIO 12", RaspiPin.GPIO_26, null));
availablePins.add(new NamedPin("GPIO 13", RaspiPin.GPIO_23, null));
availablePins.add(new NamedPin("GPIO 16", RaspiPin.GPIO_27, null));
availablePins.add(new NamedPin("GPIO 17", RaspiPin.GPIO_00, null));
availablePins.add(new NamedPin("GPIO 19", RaspiPin.GPIO_24, null));
availablePins.add(new NamedPin("GPIO 21", RaspiPin.GPIO_29, null));
availablePins.add(new NamedPin("GPIO 20", RaspiPin.GPIO_28, null));
availablePins.add(new NamedPin("GPIO 22", RaspiPin.GPIO_03, null));
availablePins.add(new NamedPin("GPIO 23", RaspiPin.GPIO_04, null));
availablePins.add(new NamedPin("GPIO 24", RaspiPin.GPIO_05, null));
availablePins.add(new NamedPin("GPIO 25", RaspiPin.GPIO_06, null));
availablePins.add(new NamedPin("GPIO 26", RaspiPin.GPIO_25, null));
availablePins.add(new NamedPin("GPIO 27", RaspiPin.GPIO_02, null));
}
示例6: RGBLed
import com.pi4j.io.gpio.GpioFactory; //導入依賴的package包/類
public RGBLed(DiodeType type,Pin red,Pin green,Pin blue) {
this.type = type;
this.pinR = red;
this.pinG = green;
this.pinB = blue;
this.color = LedColor.OFF;
gpio = GpioFactory.getInstance();
int defaultValue = (DiodeType.ANODE_COMMON.equals(type)) ? 1 : 0;
PinState defaultState = (DiodeType.ANODE_COMMON.equals(type)) ? PinState.HIGH : PinState.LOW;
outRed = gpio.provisionSoftPwmOutputPin(pinR, "Red", defaultValue);
outRed.setShutdownOptions(true, defaultState, PinPullResistance.OFF);
outGreen = gpio.provisionSoftPwmOutputPin(pinG, "Green", defaultValue);
outGreen.setShutdownOptions(true, defaultState, PinPullResistance.OFF);
outBlue = gpio.provisionSoftPwmOutputPin(pinB, "Blue", defaultValue);
outBlue.setShutdownOptions(true, defaultState, PinPullResistance.OFF);
}
示例7: IRSend
import com.pi4j.io.gpio.GpioFactory; //導入依賴的package包/類
public IRSend(Pin pin, PWMType type, int carrierFrequency) {
this.pin = pin;
gpio = GpioFactory.getInstance();
if (PWMType.SOFTWARE.equals(type))
pwm = gpio.provisionSoftPwmOutputPin(pin, "IR_PWM", 0);
else
pwm = gpio.provisionPwmOutputPin(pin, "IR_PWM", 0);
pwm.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
pwm.setPwm(0);
Gpio.pwmSetMode(Gpio.PWM_MODE_MS);
Gpio.pwmSetRange(MAX_PWM_LEVEL);
setFrequency(carrierFrequency);
if (log.isLoggable(Level.INFO)) {
log.log(Level.INFO, "IR LED pin "+pin+" PWM type "+type+" carrier frequency "+carrierFrequency+" Hz");
}
}
示例8: init
import com.pi4j.io.gpio.GpioFactory; //導入依賴的package包/類
public void init() throws IOException {
if (isRunning())
throw new IOException("Already running!");
if (gpio==null)
gpio = GpioFactory.getInstance();
mfrc522 = new MFRC522(gpio,pinNRSTPD,spiChannel);
final AtomicBoolean newThreadRunning = new AtomicBoolean(true);
Thread pooling_thread = new Thread(()->{ checkRFIDContinuously(mfrc522,newThreadRunning,callback); });
pooling_thread.setName("RFIDPooling");
pooling_thread.setDaemon(true);
pooling_thread.start();
currentThreadRunning = newThreadRunning;
}
示例9: MotorControllerImpl
import com.pi4j.io.gpio.GpioFactory; //導入依賴的package包/類
public MotorControllerImpl(PWMOutput output,
MotorControllerConfiguration configuration) {
this.output = output;
this.configuration = configuration;
this.gpio = GpioFactory.getInstance();
try {
Pin myGPIOMotorPin = (Pin) FieldUtils.readDeclaredStaticField(
RaspiPin.class, configuration.gpioPin());
motorPin = gpio.provisionDigitalOutputPin(myGPIOMotorPin,
configuration.name(), PinState.LOW);
motorPin.setShutdownOptions(true, PinState.LOW);
} catch (IllegalAccessException e) {
LOGGER.error("Error on construct MotorControllerImpl", e);
}
}
示例10: Led
import com.pi4j.io.gpio.GpioFactory; //導入依賴的package包/類
/**
* Constructs a led with its number
* @param ledNb the led number (1 or 2)
*/
protected Led(int ledNb) {
GpioController gpio = GpioFactory.getInstance();
// provision the corresponding gpio pin as an output pin
// and make sure it is set to LOW at startup
if(ledNb == 1) {
ledOutputPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, "led1", PinState.LOW);
} else {
ledOutputPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_02, "led2", PinState.LOW);
}
// configure the pin shutdown behavior; these settings will be
// automatically applied to the pin when the application is terminated
// ensure that the LED is turned OFF when the application is shutdown
ledOutputPin.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
}
示例11: main
import com.pi4j.io.gpio.GpioFactory; //導入依賴的package包/類
public static void main(String args[]) throws Exception {
System.out.println("<--Pi4J--> MCP4725 DAC Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// create gpio provider
final MCP4725GpioProvider gpioProvider = new MCP4725GpioProvider(I2CBus.BUS_1, MCP4725GpioProvider.MCP4725_ADDRESS_1);
// create output pin
final GpioPinAnalogOutput vout = gpio.provisionAnalogOutputPin(gpioProvider, MCP4725Pin.OUTPUT);
// generate sinus wave on output pin
for (int i = 0; i < 360; i++) {
double y = Math.sin(Math.toRadians(i));
y = y / 2 + 0.5;
vout.setValue(y);
if (i == 359) {
i = 0;
}
}
}
示例12: main
import com.pi4j.io.gpio.GpioFactory; //導入依賴的package包/類
public static void main(String[] args) {
System.out.println("<--Pi4J--> GPIO Frequency Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// provision gpio pin #01 as an output pin and turn on
final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, PinState.LOW);
// continuous loop
while(true) {
pin.setState(true);
pin.setState(false);
}
// stop all GPIO activity/threads by shutting down the GPIO controller
// (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
// gpio.shutdown(); <--- implement this method call if you wish to terminate the Pi4J GPIO controller
}
示例13: RasPi
import com.pi4j.io.gpio.GpioFactory; //導入依賴的package包/類
public RasPi(String n) {
super(n);
Platform platform = Platform.getLocalInstance();
log.info(String.format("platform is %s", platform));
if ("arm".equals(platform.getArch())) {
// init I2C
gpio = GpioFactory.getInstance();
gpio01 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);
gpio03 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03);
} else {
// we should be running on a Raspberry Pi
log.error("architecture is not arm");
}
}
示例14: init
import com.pi4j.io.gpio.GpioFactory; //導入依賴的package包/類
public void init(){
try {
_gpioController = GpioFactory.getInstance();
_i2cbus = I2CFactory.getInstance(I2CBus.BUS_1);
_temperatureSensor = _i2cbus.getDevice(0x40);
_lightActuator = _gpioController.provisionDigitalMultipurposePin(RaspiPin.GPIO_00, "led", PinMode.DIGITAL_OUTPUT);
_lightActuator.setShutdownOptions(true); // unexport on shutdown
// monitor temperature changes
// every change of more than 0.1C will notify SensorChangedListeners
_scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
_handle = _scheduledThreadPoolExecutor.scheduleAtFixedRate(temperatureReader, 0, 100, TimeUnit.MILLISECONDS);
} catch (IOException e) {
log.error("An error occurred whilst trying to read temperature from GPIO Pins.");
}
}
示例15: GPIOButton
import com.pi4j.io.gpio.GpioFactory; //導入依賴的package包/類
/**
* Constructing a software representation of an GPIO connected hardware
* button.
*
* @param pin
* the GPIO pin that the button is connected to.
*/
public GPIOButton(Pin pin) {
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// provision gpio pin as an input pin with its internal pull down
// resistor enabled
final GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(pin, PinPullResistance.PULL_DOWN);
// register an anonymous listener with the pi4j library to connect to
// our internal listeners.
myButton.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
event.getState();
if (event.getState() == PinState.HIGH) {
setState(ButtonState.ON);
} else {
setState(ButtonState.OFF);
}
}
});
}