本文整理汇总了Java中com.pi4j.wiringpi.Gpio.wiringPiSetup方法的典型用法代码示例。如果您正苦于以下问题:Java Gpio.wiringPiSetup方法的具体用法?Java Gpio.wiringPiSetup怎么用?Java Gpio.wiringPiSetup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.pi4j.wiringpi.Gpio
的用法示例。
在下文中一共展示了Gpio.wiringPiSetup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String args[]) throws InterruptedException {
int pin;
int dataPtr;
int l, s, d;
System.out.println("<--Pi4J--> GPIO ALT MODE test program");
// setup wiringPi
if (Gpio.wiringPiSetup() == -1) {
System.out.println(" ==>> GPIO SETUP FAILED");
return;
}
// NOTE, this example does not really do anything visible, its just an usage example of settings ALT pin modes
// iterate through all the available pin modes
Gpio.pinMode (7, Gpio.INPUT);
Gpio.pinMode (7, Gpio.OUTPUT);
Gpio.pinMode (7, Gpio.ALT0);
Gpio.pinMode (7, Gpio.ALT1);
Gpio.pinMode (7, Gpio.ALT2);
Gpio.pinMode (7, Gpio.ALT3);
Gpio.pinMode (7, Gpio.ALT4);
Gpio.pinMode (7, Gpio.ALT5);
System.out.println("Exiting WiringPiPinAltExample");
}
示例2: main
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String[] args) throws PlatformAlreadyAssignedException {
// Default platform is Raspberry -> Explicit assign the target platform
// TODO : Use PI4J_PLATFORM env variable ??
PlatformManager.setPlatform(Platform.ODROID);
// PI4J Init
if (Gpio.wiringPiSetup() == -1) {
log.error(" ==>> GPIO SETUP FAILED");
return;
}
// GPIO 1 init as Output
GpioUtil.export(1, GpioUtil.DIRECTION_OUT);
Gpio.pinMode (1, Gpio.OUTPUT) ;
// Force low state for GPIO 1
Gpio.digitalWrite(1, Gpio.LOW);
// Vertx event timer
Vertx.vertx().setPeriodic(1000, l -> {
// Blink led every seconds
if (Gpio.digitalRead(1) != Gpio.LOW) {
log.info("Switch off ...");
Gpio.digitalWrite(1, Gpio.LOW);
}
else {
log.info("Switch on ...");
Gpio.digitalWrite(1, Gpio.HIGH);
}
});
}
示例3: ServoMotorCallibration
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
/**
* Constructor for a new callibrator.
* @param minValue the minimum pulse length value, in ms.
* @param maxValue the maximum pulse length value, in ms.
*/
public ServoMotorCallibration(int minValue, int maxValue) {
this.minValue = minValue;
this.maxValue = maxValue;
Gpio.wiringPiSetup();
pinNumber = PWMPin.PWM1.getPin().getWiringPiNb();
Gpio.pinMode(pinNumber, Gpio.PWM_OUTPUT);
Gpio.pwmSetMode(Gpio.PWM_MODE_MS);
int pwmRangeGenerator = 20000;// 20ms
int targetFrequency = 50; // Hz
int pwmClockDivisor = ServoMotor.DEFAULT_RPI_PWM_CLOCK_FREQUENCY / (targetFrequency * pwmRangeGenerator);
Gpio.pwmSetClock(pwmClockDivisor);
Gpio.pwmSetRange(pwmRangeGenerator);
}
示例4: PWMComponent
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
/**
* Constructor for a PWM component, using a RPi hardware PWM pin to generate PWM signals.
* <p><b>Advantage:</b> wide range of PWM frequencies, with continuous values.</p>
* <p><b>Disadvantage:</b> only 2 hardware PWM pins on recent RPi.</p>
* @param pin the PWMPin used to generate PWM signal.
* @param rangeGenerator the value used to define the range of values that can be used
* to define a signal. The tick when the signal turn off for each pulse must then be between 0 and rangeGenerator.
* Must be >= 1.
* @see PWMPin
*/
public PWMComponent(PWMPin pin, int rangeGenerator) {
this.selectedMode = RPI_PWM_PIN_MODE;
this.pin = pin;
this.pinNumber = pin.getPin().getWiringPiNb();
this.rangeGenerator = Math.max(rangeGenerator, 1);
// Gpio setup
Gpio.wiringPiSetup(); // we need to initialize wiringPi
Gpio.pinMode(pin.getPin().getWiringPiNb(), Gpio.PWM_OUTPUT);
Gpio.pwmSetMode(Gpio.PWM_MODE_MS);
Gpio.pwmSetRange(rangeGenerator);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {stop = true;setPWM(0);}));
}
示例5: wiringPiSetup
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
protected static void wiringPiSetup(){
if (Gpio.wiringPiSetup() == -1) {
String msg = "==>> GPIO SETUP FAILED";
logger.debug(msg);
throw new RuntimeException(msg);
}
}
示例6: verifySetup
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
@Test
@Category(FastTest.class)
public void verifySetup(){
sketch.setup(NO_ARGS);
PowerMockito.verifyStatic();
Gpio.wiringPiSetup();
verify(mocked_gpioController).provisionDigitalInputPin(RaspiPin.GPIO_00);
verify(mocked_gpioController).provisionDigitalOutputPin(RaspiPin.GPIO_01);
verifyNoMoreInteractions(mocked_gpioController);
}
示例7: verifySetup
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
@Test
public void verifySetup(){
sketch.setup(NO_ARGS);
PowerMockito.verifyStatic();
Gpio.wiringPiSetup();
verify(mocked_gpioController).provisionDigitalOutputPin(RaspiPin.GPIO_00);
verify(mocked_gpioController).provisionDigitalOutputPin(RaspiPin.GPIO_01);
verify(mocked_gpioController).provisionDigitalMultipurposePin(
RaspiPin.GPIO_02, PinMode.DIGITAL_OUTPUT);
verifyNoMoreInteractions(mocked_gpioController);
}
示例8: verifySetup
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
@Test
@Category(SlowTest.class)
public void verifySetup(){
sketch.setup(NO_ARGS);
PowerMockito.verifyStatic();
Gpio.wiringPiSetup();
verify(mocked_gpioController).provisionDigitalOutputPin(RaspiPin.GPIO_00);
verify(mocked_gpioController).provisionDigitalOutputPin(RaspiPin.GPIO_01);
verify(mocked_gpioController).provisionDigitalMultipurposePin(
RaspiPin.GPIO_02, PinMode.DIGITAL_OUTPUT);
verifyNoMoreInteractions(mocked_gpioController);
}
示例9: verifySetup
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
@Test
@Category(FastTest.class)
public void verifySetup(){
sketch.setup(NO_ARGS);
PowerMockito.verifyStatic();
Gpio.wiringPiSetup();
PowerMockito.verifyStatic();
SoftPwm.softPwmCreate(LEDPINRED, 0, 100);
PowerMockito.verifyStatic();
SoftPwm.softPwmCreate(LEDPINYELLOW, 0, 100);
}
示例10: verifySetup
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
@Test
@Category(FastTest.class)
public void verifySetup(){
sketch.setup(NO_ARGS);
PowerMockito.verifyStatic();
Gpio.wiringPiSetup();
PowerMockito.verifyStatic();
SoftPwm.softPwmCreate(LEDPINRED, 0, 100);
PowerMockito.verifyStatic();
SoftPwm.softPwmCreate(LEDPINGREEN, 0, 100);
PowerMockito.verifyStatic();
SoftPwm.softPwmCreate(LEDPINBLUE, 0, 100);
}
示例11: main
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException
{
Gpio.wiringPiSetup();
SoftTone.softToneCreate(PIEZO_PIN);
RingToneTextTransferLanguage app = new RingToneTextTransferLanguage();
app.play_rtttl(song);
System.out.println("Done.");
// get rid of this comment if the tone stops at the end of play_rtttl()
// SoftTone.softToneStop(PIEZO_PIN);
}
示例12: main
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException
{
Gpio.wiringPiSetup();
// wiringPiSetup () ;
int [] scale
=
{
659, 659, 0, 659, 0, 523, 659, 0, 784, 0, 0, 0, 392, 0, 0, 0, 523, 0, 0, 392, 0, 0, 330
};
// int scale [23] = { 659, 659, 0, 659, 0, 523, 659, 0, 784, 0,0,0, 392, 0,0,0, 523, 0,0, 392, 0,0,330 } ;
int i;
SoftTone.softToneCreate(PIEZO_PIN);
// softToneCreate (PIEZO_PIN) ;
for (i = 0; i < 23; ++i)
{
System.out.printf("%3d\n", i);
SoftTone.softToneWrite(PIEZO_PIN, scale[i]);
// softToneWrite (PIEZO_PIN, scale [i]) ;
Thread.sleep(200);
// delay (200) ;
}
SoftTone.softToneStop(PIEZO_PIN);
}
示例13: main
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String args[]) throws InterruptedException {
int pin;
int dataPtr;
int l, s, d;
System.out.println("<--Pi4J--> GPIO test program");
// setup wiringPi
if (Gpio.wiringPiSetup() == -1) {
System.out.println(" ==>> GPIO SETUP FAILED");
return;
}
// set GPIO 4 as the input trigger
GpioUtil.export(7, GpioUtil.DIRECTION_IN);
GpioUtil.setEdgeDetection(7, GpioUtil.EDGE_BOTH);
Gpio.pinMode (7, Gpio.INPUT) ;
Gpio.pullUpDnControl(7, Gpio.PUD_DOWN);
// set all other GPIO as outputs
for (pin = 0; pin < 7; ++pin) {
// export all the GPIO pins that we will be using
GpioUtil.export(pin, GpioUtil.DIRECTION_OUT);
Gpio.pinMode(pin, Gpio.OUTPUT);
}
dataPtr = 0;
while (true) {
l = data[dataPtr++]; // LED
s = data[dataPtr++]; // State
d = data[dataPtr++]; // Duration (10ths)
if ((l + s + d) == 27) {
dataPtr = 0;
continue;
}
Gpio.digitalWrite(l, s);
if (Gpio.digitalRead(7) == 1) // Pressed as our switch shorts to ground
Gpio.delay(d * 10); // Faster!
else
Gpio.delay(d * 100);
}
}
示例14: main
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String args[]) throws InterruptedException, UnsupportedEncodingException {
System.out.println("<--Pi4J--> Wiring Pi LCD test program");
// setup wiringPi
if (Gpio.wiringPiSetup() == -1) {
System.out.println(" ==>> GPIO SETUP FAILED");
return;
}
// initialize LCD
int lcdHandle= Lcd.lcdInit(LCD_ROWS, // number of row supported by LCD
LCD_COLUMNS, // number of columns supported by LCD
LCD_BITS, // number of bits used to communicate to LCD
11, // LCD RS pin
10, // LCD strobe pin
0, // LCD data bit 1
1, // LCD data bit 2
2, // LCD data bit 3
3, // LCD data bit 4
0, // LCD data bit 5 (set to 0 if using 4 bit communication)
0, // LCD data bit 6 (set to 0 if using 4 bit communication)
0, // LCD data bit 7 (set to 0 if using 4 bit communication)
0); // LCD data bit 8 (set to 0 if using 4 bit communication)
// verify initialization
if (lcdHandle == -1) {
System.out.println(" ==>> LCD INIT FAILED");
return;
}
// clear LCD
Lcd.lcdClear(lcdHandle);
Thread.sleep(1000);
// write line 1 to LCD
Lcd.lcdHome(lcdHandle);
//Lcd.lcdPosition (lcdHandle, 0, 0) ;
Lcd.lcdPuts (lcdHandle, "The Pi4J Project") ;
// write line 2 to LCD
Lcd.lcdPosition (lcdHandle, 0, 1) ;
Lcd.lcdPuts (lcdHandle, "----------------") ;
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
// update time every one second
while(true){
// write time to line 2 on LCD
Lcd.lcdPosition (lcdHandle, 0, 1) ;
Lcd.lcdPuts (lcdHandle, "--- " + formatter.format(new Date()) + " ---");
Thread.sleep(1000);
}
}
示例15: main
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String args[]) throws InterruptedException {
System.out.println("<--Pi4J--> GPIO INTERRUPT test program");
// create and add GPIO listener
GpioInterrupt.addListener(new GpioInterruptListener() {
@Override
public void pinStateChange(GpioInterruptEvent event) {
System.out.println("Raspberry Pi PIN [" + event.getPin() +"] is in STATE [" + event.getState() + "]");
if(event.getPin() == 7) {
Gpio.digitalWrite(6, event.getStateValue());
}
if(event.getPin() == 0) {
Gpio.digitalWrite(5, event.getStateValue());
}
}
});
// setup wiring pi
if (Gpio.wiringPiSetup() == -1) {
System.out.println(" ==>> GPIO SETUP FAILED");
return;
}
// export all the GPIO pins that we will be using
GpioUtil.export(0, GpioUtil.DIRECTION_IN);
GpioUtil.export(7, GpioUtil.DIRECTION_IN);
GpioUtil.export(5, GpioUtil.DIRECTION_OUT);
GpioUtil.export(6, GpioUtil.DIRECTION_OUT);
// set the edge state on the pins we will be listening for
GpioUtil.setEdgeDetection(0, GpioUtil.EDGE_BOTH);
GpioUtil.setEdgeDetection(7, GpioUtil.EDGE_BOTH);
// configure GPIO pins 5, 6 as an OUTPUT;
Gpio.pinMode(5, Gpio.OUTPUT);
Gpio.pinMode(6, Gpio.OUTPUT);
// configure GPIO 0 as an INPUT pin; enable it for callbacks
Gpio.pinMode(0, Gpio.INPUT);
Gpio.pullUpDnControl(0, Gpio.PUD_DOWN);
GpioInterrupt.enablePinStateChangeCallback(0);
// configure GPIO 7 as an INPUT pin; enable it for callbacks
Gpio.pinMode(7, Gpio.INPUT);
Gpio.pullUpDnControl(7, Gpio.PUD_DOWN);
GpioInterrupt.enablePinStateChangeCallback(7);
// continuously loop to prevent program from exiting
while (true) {
Thread.sleep(5000);
}
}