本文整理匯總了Java中com.pi4j.io.gpio.RaspiPin類的典型用法代碼示例。如果您正苦於以下問題:Java RaspiPin類的具體用法?Java RaspiPin怎麽用?Java RaspiPin使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RaspiPin類屬於com.pi4j.io.gpio包,在下文中一共展示了RaspiPin類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import com.pi4j.io.gpio.RaspiPin; //導入依賴的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
}
示例2: GpioManager
import com.pi4j.io.gpio.RaspiPin; //導入依賴的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));
}
示例3: CollisionRunnable
import com.pi4j.io.gpio.RaspiPin; //導入依賴的package包/類
@Inject
public CollisionRunnable(IRSensorFactory sensorFactory,
GpioController gpio,
ClientManager clientManager,
RoverHandler roverHandler) {
LOGGER.info("creating new CollisionRunnable via injected constructor");
this.sensorFrontRight = sensorFactory.create(PCF8591ADConverter.InputChannel.ZERO,
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03, PinState.LOW));
this.sensorFrontLeft = sensorFactory.create(PCF8591ADConverter.InputChannel.ONE,
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05, PinState.LOW));
this.sensorBackRight = sensorFactory.create(PCF8591ADConverter.InputChannel.THREE,
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_29, PinState.LOW));
this.sensorBackLeft = sensorFactory.create(PCF8591ADConverter.InputChannel.TWO,
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_24, PinState.LOW));
this.clientManager = clientManager;
}
示例4: MotorControllerImpl
import com.pi4j.io.gpio.RaspiPin; //導入依賴的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);
}
}
示例5: Led
import com.pi4j.io.gpio.RaspiPin; //導入依賴的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);
}
示例6: main
import com.pi4j.io.gpio.RaspiPin; //導入依賴的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
}
示例7: P1Header
import com.pi4j.io.gpio.RaspiPin; //導入依賴的package包/類
public P1Header() {
pinConfiguration = HashBiMap.create();
pinConfiguration.put(3, RaspiPin.GPIO_08);
pinConfiguration.put(5, RaspiPin.GPIO_09);
pinConfiguration.put(7, RaspiPin.GPIO_07);
pinConfiguration.put(8, RaspiPin.GPIO_15);
pinConfiguration.put(10, RaspiPin.GPIO_16);
pinConfiguration.put(11, RaspiPin.GPIO_00);
pinConfiguration.put(12, RaspiPin.GPIO_01);
pinConfiguration.put(13, RaspiPin.GPIO_02);
pinConfiguration.put(15, RaspiPin.GPIO_03);
pinConfiguration.put(16, RaspiPin.GPIO_04);
pinConfiguration.put(18, RaspiPin.GPIO_05);
pinConfiguration.put(19, RaspiPin.GPIO_12);
pinConfiguration.put(21, RaspiPin.GPIO_13);
pinConfiguration.put(22, RaspiPin.GPIO_06);
pinConfiguration.put(23, RaspiPin.GPIO_14);
pinConfiguration.put(24, RaspiPin.GPIO_10);
pinConfiguration.put(26, RaspiPin.GPIO_11);
}
示例8: RasPi
import com.pi4j.io.gpio.RaspiPin; //導入依賴的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");
}
}
示例9: init
import com.pi4j.io.gpio.RaspiPin; //導入依賴的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.");
}
}
示例10: setup
import com.pi4j.io.gpio.RaspiPin; //導入依賴的package包/類
@Override
protected void setup(String[] args) {
wiringPiSetup();
ledPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);
sigPin = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_DOWN);
sigPin.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
if(event.getState().isLow()){
logger.debug("Magic cup connected.");
ledPin.high();
}else{
ledPin.low();
}
}
});
logger.debug("Magic cup sensor ready!");
}
示例11: setup
import com.pi4j.io.gpio.RaspiPin; //導入依賴的package包/類
@Override
protected void setup(String[] args) {
wiringPiSetup();
ledPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);
tiltSwitch = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_DOWN);
tiltSwitch.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
logger.debug("Tilt state: "+event.getState());
if(event.getState().isHigh()){
ledPin.high();
}else{
ledPin.low();
}
}
});
logger.debug("Tilt switch sensor ready!");
}
示例12: setup
import com.pi4j.io.gpio.RaspiPin; //導入依賴的package包/類
@Override
protected void setup(String[] args) {
wiringPiSetup();
ledPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);
lightBreakPin = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_DOWN);
lightBreakPin.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
if(event.getState().isHigh()){
logger.debug("Light beam is broken");
ledPin.high();
}else{
ledPin.low();
}
}
});
logger.debug("Light break ready!");
}
示例13: setup
import com.pi4j.io.gpio.RaspiPin; //導入依賴的package包/類
@Override
protected void setup(String[] args) {
if (args.length == 3) {
device_fileName = args[0];
low = Double.parseDouble(args[1]);
high = Double.parseDouble(args[2]);
if (low >= high) {
throw new RuntimeException(
"Arguments error, lower limit "
+ "should be less than upper limit. \n");
}
logger.debug("Temperature monitor ready!");
} else {
throw new RuntimeException(
"Please provide arguments \n"
+ " [ds18b20 Filename] [lower limit] [upper limit] \n"
+ "Find ds18b20 device file names at "
+ Ex16_Ds18b20.W1_DEVICES_PATH);
}
wiringPiSetup();
ledRed = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_00);
ledGreen = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);
ledBlue = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_02);
beep = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03);
logger.info("Temperature monitor ready!");
}
示例14: setup
import com.pi4j.io.gpio.RaspiPin; //導入依賴的package包/類
@Override
protected void setup(String[] args) {
super.setup(args);
if(args.length == 1){
device_fileName = args[0];
}else{
throw new RuntimeException(
"Please provide a device file name from "
+Ex16_Ds18b20.W1_DEVICES_PATH);
}
ledRed = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03);
ledGreen = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04);
ledBlue = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05);
beep = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_08);
joyStick_Z = gpio.provisionDigitalInputPin(RaspiPin.GPIO_06, PinPullResistance.PULL_UP);
joyStick_Z.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent gpdsce) {
sys_state = PinState.LOW;
logger.debug("interrupt occur !");
}
});
sys_state = PinState.HIGH;
logger.debug("Temperature monitor ready!");
}
示例15: setup
import com.pi4j.io.gpio.RaspiPin; //導入依賴的package包/類
@Override
protected void setup(String[] args) {
wiringPiSetup();
ledPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);
myButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_DOWN);
myButton.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
if(event.getState().isLow()){
logger.debug("Button is pressed");
ledPin.toggle();
}
}
});
logger.debug("Button sensor ready!");
}