本文整理汇总了Java中com.pi4j.wiringpi.Gpio.digitalWrite方法的典型用法代码示例。如果您正苦于以下问题:Java Gpio.digitalWrite方法的具体用法?Java Gpio.digitalWrite怎么用?Java Gpio.digitalWrite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.pi4j.wiringpi.Gpio
的用法示例。
在下文中一共展示了Gpio.digitalWrite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public boolean[] read() {
final boolean[] data = new boolean[8];
Gpio.digitalWrite(CLK_INH, Gpio.HIGH);
Gpio.digitalWrite(SH_LD, Gpio.LOW);
Gpio.delayMicroseconds(1);
Gpio.digitalWrite(SH_LD, Gpio.HIGH);
Gpio.digitalWrite(CLK_INH, Gpio.LOW);
for (int i = 7; i >= 0; i--) {
Gpio.digitalWrite(CLK, Gpio.HIGH);
Gpio.digitalWrite(CLK, Gpio.LOW);
data[i] = Gpio.digitalRead(QH) == Gpio.HIGH ? true : false;
}
return data;
}
示例2: getDistanceTwoPins
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
private double getDistanceTwoPins() {
Gpio.digitalWrite(trig, Gpio.LOW);
Tools.sleepMilliseconds(2);
Gpio.digitalWrite(trig, Gpio.HIGH);
Tools.sleepMilliseconds(10);
Gpio.digitalWrite(trig, Gpio.LOW);
while(!(Gpio.digitalRead(echo) == 1));
long start = System.nanoTime();
while(!(Gpio.digitalRead(echo) == 0));
long end = System.nanoTime();
return (end - start) / 1000. / 58.;
}
示例3: getDistanceOnePin
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
private double getDistanceOnePin() {
Gpio.pinMode(trig, Gpio.OUTPUT);
Gpio.digitalWrite(trig, Gpio.LOW);
Tools.sleepMilliseconds(2);
Gpio.digitalWrite(trig, Gpio.HIGH);
Tools.sleepMilliseconds(10);
Gpio.digitalWrite(trig, Gpio.LOW);
Gpio.pinMode(trig, Gpio.INPUT);
while(!(Gpio.digitalRead(trig) == 1));
long start = System.nanoTime();
while(!(Gpio.digitalRead(trig) == 0));
long end = System.nanoTime();
return (end - start) / 1000. / 58.;
}
示例4: run
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
@Override
public void run() {
System.out.println(Thread.currentThread().getName()
+ " started on PIN " + pin);
Gpio.wiringPiSetupGpio();
Gpio.pinMode(pin, Gpio.OUTPUT);
Gpio.pullUpDnControl(pin, Gpio.PUD_DOWN);
Gpio.digitalWrite(pin, true);
while (!finish) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
stop();
}
}
Gpio.digitalWrite(pin, false);
System.out.println(Thread.currentThread().getName() + " finished.");
}
示例5: gpioIsrSetup
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
private static void gpioIsrSetup() {
wiringPiSetup();
Gpio.pinMode(btnPin, Gpio.INPUT);
Gpio.pullUpDnControl(btnPin, Gpio.PUD_UP);
Gpio.pinMode(ledPin, Gpio.OUTPUT);
Gpio.pullUpDnControl(ledPin, Gpio.PUD_DOWN);
Gpio.digitalWrite(ledPin, false);
Gpio.wiringPiISR(btnPin, Gpio.INT_EDGE_FALLING, new GpioInterruptCallback() {
private final long debounceTime = 200;
@Override
public void callback(int pin) {
Gpio.delay(10);
long currentTime = System.currentTimeMillis();
if(currentTime > lastTime+debounceTime){
Gpio.digitalWrite(ledPin, Gpio.digitalRead(ledPin)==0?1:0);
logger.debug("GPIO PIN 0 detected. Led state: "+Gpio.digitalRead(ledPin));
}else{
logger.debug("Discard event "+currentTime);
}
lastTime=currentTime;
}
});
}
示例6: tearDownPins
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
private synchronized void tearDownPins(){
// turn off pen
try{
String servoPenOffCommand = buildServoCommand(properties.getPenPinNumber(), 0);
FileUtils.writeStringToFile(servoPipeFile, servoPenOffCommand);
} catch (Exception e){
throw new RuntimeException(e.getMessage());
}
Gpio.pinMode(properties.getPenPinNumber(), Gpio.OUTPUT);
Gpio.digitalWrite(properties.getLeftMotorEnablePinNumber(), false); // turn off old pin
Gpio.digitalWrite(properties.getLeftMotorDirectionPinNumber(), false); // turn off old pin
Gpio.digitalWrite(properties.getLeftMotorStepPinNumber(), false); // turn off old pin
Gpio.digitalWrite(properties.getRightMotorEnablePinNumber(), false); // turn off old pin
Gpio.digitalWrite(properties.getRightMotorDirectionPinNumber(), false); // turn off old pin
Gpio.digitalWrite(properties.getRightMotorStepPinNumber(), false); // turn off old pin
}
示例7: write
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public void write(boolean[] data) {
if (data.length != 8) {
return;
} else {
Gpio.digitalWrite(RCK, Gpio.LOW);
for (int i = 7; i >= 0; i--) {
Gpio.digitalWrite(SCK, Gpio.LOW);
Gpio.digitalWrite(SER, data[i]);
Gpio.digitalWrite(SCK, Gpio.HIGH);
}
Gpio.digitalWrite(RCK, Gpio.HIGH);
}
}
示例8: stopKeyboard
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void stopKeyboard() {
if (StaticVars.debugOn == false) {
Gpio.digitalWrite(33, false);
Gpio.digitalWrite(35, false);
Gpio.digitalWrite(36, false);
Gpio.digitalWrite(37, false);
Gpio.digitalWrite(38, false);
Gpio.digitalWrite(40, false);
}
}
示例9: 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);
}
});
}
示例10: main
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Usage: " + WiringPiRawPerfTest.class.getName() + " <pin-number> [<iterations>]");
System.exit(1);
}
final int pin = Integer.parseInt(args[0]);
final int iterations = args.length > 1 ? Integer.parseInt(args[1]) : DEFAULT_ITERATIONS;
Gpio.wiringPiSetupGpio();
if (GpioUtil.isExported(pin)) {
GpioUtil.setDirection(pin, GpioUtil.DIRECTION_OUT);
} else {
GpioUtil.export(pin, GpioUtil.DIRECTION_OUT);
}
Gpio.pinMode(pin, Gpio.OUTPUT);
for (int j=0; j<5; j++) {
long start_nano = System.nanoTime();
for (int i=0; i<iterations; i++) {
Gpio.digitalWrite(pin, true);
Gpio.digitalWrite(pin, false);
}
long duration_ns = (System.nanoTime() - start_nano);
System.out.format("Duration for %d iterations: %.4fs%n",
Integer.valueOf(iterations), Float.valueOf(((float)duration_ns) / 1000 / 1000 / 1000));
}
GpioUtil.unexport(pin);
}
示例11: runMotors
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
private void runMotors(MotorsCommand mc) {
//setting motor directions
Gpio.digitalWrite(5, mc.getDirR() > 0 ? 1 : 0);
Gpio.digitalWrite(6, mc.getDirL() > 0 ? 1 : 0);
//setting speed
if(mc.getVelocityR() >= 0 && mc.getVelocityR() <= MAX_SPEED)
Gpio.pwmWrite(12, mc.getVelocityR()); // speed up to MAX_SPEED
if(mc.getVelocityL() >= 0 && mc.getVelocityL() <= MAX_SPEED)
Gpio.pwmWrite(13, mc.getVelocityL());
}
示例12: tearDownPins
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
private synchronized void tearDownPins(){
SoftPwm.softPwmWrite(properties.getPenPinNumber(), 0);
// Set pinMode to Output to reset/PWM Pin so it doesn't fail if setup again
Gpio.pinMode(properties.getPenPinNumber(), Gpio.OUTPUT);
Gpio.digitalWrite(properties.getLeftMotorEnablePinNumber(), false); // turn off old pin
Gpio.digitalWrite(properties.getLeftMotorDirectionPinNumber(), false); // turn off old pin
Gpio.digitalWrite(properties.getLeftMotorStepPinNumber(), false); // turn off old pin
Gpio.digitalWrite(properties.getRightMotorEnablePinNumber(), false); // turn off old pin
Gpio.digitalWrite(properties.getRightMotorDirectionPinNumber(), false); // turn off old pin
Gpio.digitalWrite(properties.getRightMotorStepPinNumber(), false); // turn off old pin
}
示例13: loop
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
@Override
protected void loop(String[] args) {
try {
countDownLatchEndSketch.await();
} catch (InterruptedException ex) {
logger.error(ex.getMessage(), ex);
}
Gpio.digitalWrite(ledPin, 0);
}
示例14: 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);
}
}
示例15: startKeyboard
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public synchronized static void startKeyboard() {
final Thread kt = new Thread(() -> {
if (StaticVars.debugOn) {
try {
while (true) {
if (debugKeyCode != -1) {
debugKeyPressed(debugKeyCode);
debugKeyCode = -1;
}
Thread.sleep(50);
}
} catch (final InterruptedException e) {}
} else {
Gpio.pinMode(CLK_INH_pin, Gpio.OUTPUT);
Gpio.pinMode(RCK_pin, Gpio.OUTPUT);
Gpio.pinMode(SER_pin, Gpio.OUTPUT);
Gpio.pinMode(SH_LD_pin, Gpio.OUTPUT);
Gpio.pinMode(SCK_and_CLK_pin, Gpio.OUTPUT);
Gpio.pinMode(QH_pin, Gpio.INPUT);
Gpio.digitalWrite(CLK_INH_pin, false);
Gpio.digitalWrite(RCK_pin, false);
Gpio.digitalWrite(SER_pin, false);
Gpio.digitalWrite(SH_LD_pin, false);
Gpio.digitalWrite(SCK_and_CLK_pin, false);
Gpio.digitalWrite(QH_pin, false);
final SerialToParallel chip1 = new SerialToParallel(RCK_pin, SCK_and_CLK_pin /*SCK*/, SER_pin);
final ParallelToSerial chip2 = new ParallelToSerial(SH_LD_pin, CLK_INH_pin, QH_pin, SCK_and_CLK_pin/*CLK*/);
KeyboardDebugScreen.log("Started keyboard system");
while (true) {
boolean[] data;
for (int col = 0; col < 8; col++) {
data = new boolean[8];
data[col] = true;
chip1.write(data);
data = chip2.read();
// KeyboardDebugScreen.ks[col] = data;
for (int row = 0; row < 8; row++) {
if (data[row] == true && precedentStates[row][col] == false) {
// System.out.println("Pressed button at " + (row + 1) + ", " + (col + 1));
// KeyboardDebugScreen.log("Pressed button at " + (row + 1) + ", " + (col + 1));
keyPressedRaw(row, col);
} else if (data[row] == false && precedentStates[row][col] == true) {
keyReleasedRaw(row, col);
// KeyboardDebugScreen.log("Released button at " + (row + 1) + ", " + (col + 1));
}
precedentStates[row][col] = data[row];
}
}
}
}
});
kt.setName("Keyboard thread");
kt.setPriority(Thread.NORM_PRIORITY + 1);
kt.setDaemon(true);
kt.start();
}