本文整理汇总了Java中com.pi4j.io.gpio.PinState类的典型用法代码示例。如果您正苦于以下问题:Java PinState类的具体用法?Java PinState怎么用?Java PinState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PinState类属于com.pi4j.io.gpio包,在下文中一共展示了PinState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.pi4j.io.gpio.PinState; //导入依赖的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: PumpDiagGuiSingle
import com.pi4j.io.gpio.PinState; //导入依赖的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);
}
示例3: getNextOutput
import com.pi4j.io.gpio.PinState; //导入依赖的package包/类
public GpioPinDigitalOutput getNextOutput() {
// No pins are left
if (this.availablePins.isEmpty()) {
return null;
}
NamedPin temp = this.availablePins.get(0);
this.assignedPins.add(temp);
this.availablePins.remove(temp);
GpioPinDigitalOutput result;
if(temp.provider != null){
result = this.gpio.provisionDigitalOutputPin(temp.provider, temp.pin, PinState.LOW);
} else {
result = this.gpio.provisionDigitalOutputPin(temp.pin, PinState.LOW);
}
return result;
}
示例4: RGBLed
import com.pi4j.io.gpio.PinState; //导入依赖的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);
}
示例5: IRSend
import com.pi4j.io.gpio.PinState; //导入依赖的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");
}
}
示例6: CollisionRunnable
import com.pi4j.io.gpio.PinState; //导入依赖的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;
}
示例7: MotorControllerImpl
import com.pi4j.io.gpio.PinState; //导入依赖的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);
}
}
示例8: testSetSpeed
import com.pi4j.io.gpio.PinState; //导入依赖的package包/类
@Test
public void testSetSpeed() throws IOException {
motorController.setSpeed(MotorController.SPEED_STOP);
assertThat(pwmGenDeviceMock.getOnTimerValue(CHANNEL), is(0));
assertThat(pwmGenDeviceMock.getOffTimerValue(CHANNEL), is(0));
assertThat(directionPinMock.getState(), is(PinState.HIGH));
motorController.setSpeed(MotorController.SPEED_MAX_FORWARD);
assertThat(pwmGenDeviceMock.getOnTimerValue(CHANNEL), is(0));
assertThat(pwmGenDeviceMock.getOffTimerValue(CHANNEL), is(4096));
assertThat(directionPinMock.getState(), is(PinState.HIGH));
motorController.setSpeed(MotorController.SPEED_MAX_BACKWARD);
assertThat(pwmGenDeviceMock.getOnTimerValue(CHANNEL), is(0));
assertThat(pwmGenDeviceMock.getOffTimerValue(CHANNEL), is(4096));
assertThat(directionPinMock.getState(), is(PinState.LOW));
}
示例9: testSetSpeedReversed
import com.pi4j.io.gpio.PinState; //导入依赖的package包/类
@Test
public void testSetSpeedReversed() throws IOException {
configuration.reversed = true;
motorController.setSpeed(MotorController.SPEED_STOP);
assertThat(pwmGenDeviceMock.getOnTimerValue(CHANNEL), is(0));
assertThat(pwmGenDeviceMock.getOffTimerValue(CHANNEL), is(0));
assertThat(directionPinMock.getState(), is(PinState.LOW));
motorController.setSpeed(MotorController.SPEED_MAX_FORWARD);
assertThat(pwmGenDeviceMock.getOnTimerValue(CHANNEL), is(0));
assertThat(pwmGenDeviceMock.getOffTimerValue(CHANNEL), is(4096));
assertThat(directionPinMock.getState(), is(PinState.LOW));
motorController.setSpeed(MotorController.SPEED_MAX_BACKWARD);
assertThat(pwmGenDeviceMock.getOnTimerValue(CHANNEL), is(0));
assertThat(pwmGenDeviceMock.getOffTimerValue(CHANNEL), is(4096));
assertThat(directionPinMock.getState(), is(PinState.HIGH));
}
示例10: Led
import com.pi4j.io.gpio.PinState; //导入依赖的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.PinState; //导入依赖的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
}
示例12: start
import com.pi4j.io.gpio.PinState; //导入依赖的package包/类
@Override
public void start() {
bufferZeroInterrupt.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
// display pin state on console
//System.out.println(" --> MESSAGE RECEIVED: " + event.getPin() + " = " + event.getState());
if(event.getState() == PinState.LOW) {
//Message is in RX0
manager.submitRead(readBufferZero());
}
}
});
}
示例13: rotaryDeal
import com.pi4j.io.gpio.PinState; //导入依赖的package包/类
private void rotaryDeal() {
lastRoBStatus = roBPin.getState();
while(roAPin.isLow()){
currentRoBStatus = roBPin.getState();
flag=true;
}
if(flag){
flag = false;
if(lastRoBStatus==PinState.LOW && currentRoBStatus==PinState.HIGH){
globalCounter ++;
}
if(lastRoBStatus==PinState.HIGH && currentRoBStatus==PinState.LOW){
globalCounter --;
}
}
}
示例14: setup
import com.pi4j.io.gpio.PinState; //导入依赖的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: testNotMagneticFieldInteraction
import com.pi4j.io.gpio.PinState; //导入依赖的package包/类
@Test
public void testNotMagneticFieldInteraction() throws InterruptedException {
prepareMockedPins();
when(mocked_ADC_DIO.getState()).thenReturn(PinState.LOW);
sketch.setup(NO_ARGS);
sketch.setSketchInterruption();
sketch.loop();
verify(mocked_ADC_DIO, times(2)).setMode(PinMode.DIGITAL_OUTPUT);
verify(mocked_ADC_CS).low();
verify(mocked_ADC_CLK, times(20)).low();
verify(mocked_ADC_CLK, times(19)).high();
verify(mocked_ADC_DIO, times(2)).high();
verify(mocked_ADC_DIO).low();
verify(mocked_ADC_DIO).setMode(PinMode.DIGITAL_INPUT);
verify(mocked_ADC_CS).high();
}