当前位置: 首页>>代码示例>>Java>>正文


Java Gpio.wiringPiSetupGpio方法代码示例

本文整理汇总了Java中com.pi4j.wiringpi.Gpio.wiringPiSetupGpio方法的典型用法代码示例。如果您正苦于以下问题:Java Gpio.wiringPiSetupGpio方法的具体用法?Java Gpio.wiringPiSetupGpio怎么用?Java Gpio.wiringPiSetupGpio使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.pi4j.wiringpi.Gpio的用法示例。


在下文中一共展示了Gpio.wiringPiSetupGpio方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public void test(int gpio) {
	int status = Gpio.wiringPiSetupGpio();
	if (status != 0) {
		throw new RuntimeException("Error initialising wiringPi: " + status);
	}
	Gpio.pinMode(gpio, Gpio.INPUT);
	Gpio.pullUpDnControl(gpio, Gpio.PUD_UP);
	int delay = 20;
	System.out.println("Waiting " + delay + "s for events..., thread name=" + Thread.currentThread().getName());
	if (Gpio.wiringPiISR(gpio, Gpio.INT_EDGE_BOTH, this) != 1) {
		System.out.println("Error in wiringPiISR");
	} else {
		System.out.println("Sleeping for " + delay + "s");
		SleepUtil.sleepSeconds(delay);
	}
	
	GpioUtil.unexport(gpio);
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:19,代码来源:ButtonTestWiringPi.java

示例2: main

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String[] args) {
	int pin_number = 13;
	
	Gpio.wiringPiSetupGpio();
	Gpio.pinMode(pin_number, Gpio.PWM_OUTPUT);
	Gpio.pwmSetMode(Gpio.PWM_MODE_MS);
	//Gpio.pwmSetClock(384);
	//Gpio.pwmSetRange(1000);
	Gpio.pwmSetClock(187);
	Gpio.pwmSetRange(1024);
	
	
	try {
		for (int i=0; i<1000; i+=10) {
			Gpio.pwmWrite(pin_number, i);
			Thread.sleep(100);
		}
		for (int i=1000; i>0; i-=10) {
			Gpio.pwmWrite(pin_number, i);
			Thread.sleep(100);
		}
	} catch (InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:27,代码来源:Pi4jPwmTest.java

示例3: 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.");
}
 
开发者ID:iproduct,项目名称:course-social-robotics,代码行数:22,代码来源:CoctailMachine.java

示例4: WiringPiDeviceFactory

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public WiringPiDeviceFactory() {
	// Initialise using native pin numbering scheme
	int status = Gpio.wiringPiSetupGpio();
	if (status != 0) {
		throw new RuntimeException("Error initialising wiringPi: " + status);
	}
	
	// Default mode is balanced, actually want mark-space which gives traditional PWM with
	// predictable PWM frequencies
	setHardwarePwmFrequency(DEFAULT_HARDWARE_PWM_FREQUENCY);
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:12,代码来源:WiringPiDeviceFactory.java

示例5: 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);
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:31,代码来源:WiringPiRawPerfTest.java

示例6: main

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String[] args) {
	// initialize wiringPi library
	Gpio.wiringPiSetupGpio();
	
	// US distance sensor GPIO output pin - switch US off
	Gpio.pinMode(14, Gpio.OUTPUT);
	Gpio.digitalWrite(14, false);
	
	try {
		IPTPIDemo demo = new IPTPIDemo();
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:iproduct,项目名称:course-social-robotics,代码行数:15,代码来源:IPTPIDemo.java

示例7: main

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String args[]) throws InterruptedException {

		// !! ATTENTION !!
		// By default, the serial port is configured as a console port
		// for interacting with the Linux OS shell. If you want to use
		// the serial port in a software program, you must disable the
		// OS from using this port. Please see this blog article by
		// Clayton Smith for step-by-step instructions on how to disable
		// the OS console for this port:
		// http://www.irrational.net/2012/04/19/using-the-raspberry-pis-serial-port/

		// initialize wiringPi library
		Gpio.wiringPiSetupGpio();

		// GPIO output pin
		Gpio.pinMode(14, Gpio.OUTPUT);
		Gpio.digitalWrite(14, false);

		System.out.println("<--Pi4J--> Serial Communication Example ... started.");
		System.out.println(" ... connect using settings: 9600, N, 8, 1.");
		System.out.println(" ... data received on serial port should be displayed below.");

		// create an instance of the serial communications class
		final Serial serial = SerialFactory.createInstance();
		SerialConfig conf = new SerialConfig();
		conf.baud(Baud._9600);	
		conf.device(Serial.DEFAULT_COM_PORT);
		conf.flowControl(FlowControl.NONE);
		conf.dataBits(DataBits._8);
		conf.stopBits(StopBits._1);
		conf.parity(Parity.NONE);

		// create and register the serial data listener
		SerialDataEventListener listener = new SerialDataEventListener() {

			@Override
			public void dataReceived(SerialDataEvent event) {
				// print out the data received to the console
				byte[] reading;
				try {
					reading = event.getBytes();
					System.out.println(new String(reading, Charset.forName("UTF-8")));
//					System.out.println(Arrays.toString(reading));
				} catch (IOException e1) {
					e1.printStackTrace();
				}
			}
		};
		
		serial.addListener(listener);

		try {
			// open the default serial port provided on the GPIO header
			serial.open(conf);
			System.out.println("Demo running ... ");
			
			for (int i = 0; i < 50; i++) {
				Gpio.digitalWrite(14, true);
				Thread.sleep(40);
				Gpio.digitalWrite(14, false);
				Thread.sleep(500);
			}
			serial.discardInput();
			serial.removeListener(listener);
			serial.close();
			System.out.println("Demo finished.");

		} catch (IOException ex) {
			ex.printStackTrace();
		} finally {
			System.out.println("End of program");
			System.exit(0);
		}
	}
 
开发者ID:iproduct,项目名称:course-social-robotics,代码行数:75,代码来源:SerialExample.java

示例8: main

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {

		// initialize wiringPi library
		Gpio.wiringPiSetupGpio();

		// GPIO output pin
		Gpio.pinMode(17, Gpio.OUTPUT);
		Gpio.pullUpDnControl(17, Gpio.PUD_DOWN);
		Gpio.digitalWrite(17, false);

		for (int i = 0; i < 30; i++) {
			System.out.println("Iteration " + i);
			Gpio.digitalWrite(17, true);
			Thread.sleep(60000);
			Gpio.digitalWrite(17, false);
			Thread.sleep(500);
		}
		Gpio.digitalWrite(17, false);

		// Gpio.digitalWrite(6, 1);
		//
		// Gpio.pwmWrite(12, 240);
		// Gpio.pwmWrite(13, 240);
		// // SoftPwm.softPwmWrite(12, i);
		// Thread.sleep(5000);
		//
		// System.out.println("Running motors forward accelerating");
		//
		// for (int i = 0; i <= 480; i++) {
		// Gpio.digitalWrite(5, 1);
		// Gpio.digitalWrite(6, 1);
		//
		// Gpio.pwmWrite(12, i);
		// Gpio.pwmWrite(13, i);
		// // SoftPwm.softPwmWrite(12, i);
		// Thread.sleep(40);
		// }
		//
		// System.out.println("Running motors forward decelerating");
		// for (int i = 480; i > 0; i--) {
		// Gpio.digitalWrite(5, 1);
		// Gpio.digitalWrite(6, 1);
		//
		// Gpio.pwmWrite(12, i);
		// Gpio.pwmWrite(13, i);
		// // SoftPwm.softPwmWrite(12, i);
		// Thread.sleep(20);
		// }
		//
		// Gpio.digitalWrite(5, 0);
		// Gpio.digitalWrite(6, 1);
		//
		// Gpio.pwmWrite(12, 240);
		// Gpio.pwmWrite(13, 240);
		// // SoftPwm.softPwmWrite(12, i);
		// Thread.sleep(5000);
		//
		// System.out.println("Running motors forward decelerating");
		// for (int i = 480; i > 0; i--) {
		// Gpio.digitalWrite(5, 1);
		// Gpio.digitalWrite(6, 1);
		//
		// Gpio.pwmWrite(12, i);
		// Gpio.pwmWrite(13, i);
		// // SoftPwm.softPwmWrite(12, i);
		// Thread.sleep(50);
		// }
		//
		// Gpio.digitalWrite(5, 0);
		// Gpio.digitalWrite(6, 0);
		// Gpio.pwmWrite(12, 0);
		// Gpio.pwmWrite(13, 0);

		System.out.println("End of the demo.");

	}
 
开发者ID:iproduct,项目名称:course-social-robotics,代码行数:77,代码来源:AudioDemo.java

示例9: main

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {

		// initialize wiringPi library
		Gpio.wiringPiSetupGpio();

		// GPIO output pin
		Gpio.pinMode(4, Gpio.OUTPUT);

		for (int i = 0; i < 10; i++) {
			Gpio.digitalWrite(4, true);
			Thread.sleep(1000);
			Gpio.digitalWrite(4, false);
			Thread.sleep(1000);
		}
		Gpio.digitalWrite(4, false);

		// Gpio.digitalWrite(6, 1);
		//
		// Gpio.pwmWrite(12, 240);
		// Gpio.pwmWrite(13, 240);
		// // SoftPwm.softPwmWrite(12, i);
		// Thread.sleep(5000);
		//
		// System.out.println("Running motors forward accelerating");
		//
		// for (int i = 0; i <= 480; i++) {
		// Gpio.digitalWrite(5, 1);
		// Gpio.digitalWrite(6, 1);
		//
		// Gpio.pwmWrite(12, i);
		// Gpio.pwmWrite(13, i);
		// // SoftPwm.softPwmWrite(12, i);
		// Thread.sleep(40);
		// }
		//
		// System.out.println("Running motors forward decelerating");
		// for (int i = 480; i > 0; i--) {
		// Gpio.digitalWrite(5, 1);
		// Gpio.digitalWrite(6, 1);
		//
		// Gpio.pwmWrite(12, i);
		// Gpio.pwmWrite(13, i);
		// // SoftPwm.softPwmWrite(12, i);
		// Thread.sleep(20);
		// }
		//
		// Gpio.digitalWrite(5, 0);
		// Gpio.digitalWrite(6, 1);
		//
		// Gpio.pwmWrite(12, 240);
		// Gpio.pwmWrite(13, 240);
		// // SoftPwm.softPwmWrite(12, i);
		// Thread.sleep(5000);
		//
		// System.out.println("Running motors forward decelerating");
		// for (int i = 480; i > 0; i--) {
		// Gpio.digitalWrite(5, 1);
		// Gpio.digitalWrite(6, 1);
		//
		// Gpio.pwmWrite(12, i);
		// Gpio.pwmWrite(13, i);
		// // SoftPwm.softPwmWrite(12, i);
		// Thread.sleep(50);
		// }
		//
		// Gpio.digitalWrite(5, 0);
		// Gpio.digitalWrite(6, 0);
		// Gpio.pwmWrite(12, 0);
		// Gpio.pwmWrite(13, 0);

		System.out.println("End of the demo.");

	}
 
开发者ID:iproduct,项目名称:course-social-robotics,代码行数:74,代码来源:LEDDemo01.java

示例10: setupPins

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
private synchronized void setupPins() {
	int retryCount=0;
	while(true){
		try{
			int ret = Gpio.wiringPiSetupGpio();
			if (ret==0) break;
			System.out.println("Error Initializing GPIO!");
		} catch (Throwable t){
			System.out.println("Error Initializing GPIO! " + toString());
		}
		if (retryCount>3){
			throw new RuntimeException("Count not Initialize GPIO!");
		}
		System.out.println("Trying again!");
		retryCount++;
		try{Thread.sleep(500);} catch (Exception e){}
	}
	
	servoPipeFile = new File(properties.getServoDevicePipe());
	if ((!servoPipeFile.exists()) || (!servoPipeFile.canWrite())){
		throw new RuntimeException("Can not write to Servo Device Pipe: " + properties.getServoDevicePipe() + "! Make sure the 'pigpiod' service is running!");
	}
	
	Gpio.pinMode(properties.getLeftMotorEnablePinNumber(), Gpio.OUTPUT);
	Gpio.digitalWrite(properties.getLeftMotorEnablePinNumber(), false);

	Gpio.pinMode(properties.getLeftMotorDirectionPinNumber(), Gpio.OUTPUT);
	Gpio.digitalWrite(properties.getLeftMotorDirectionPinNumber(), false);
		
	Gpio.pinMode(properties.getLeftMotorStepPinNumber(), Gpio.OUTPUT);
	Gpio.digitalWrite(properties.getLeftMotorStepPinNumber(), false);
		
	Gpio.pinMode(properties.getRightMotorEnablePinNumber(), Gpio.OUTPUT);
	Gpio.digitalWrite(properties.getRightMotorEnablePinNumber(), false);

	Gpio.pinMode(properties.getRightMotorDirectionPinNumber(), Gpio.OUTPUT);
	Gpio.digitalWrite(properties.getRightMotorDirectionPinNumber(), false);

	Gpio.pinMode(properties.getRightMotorStepPinNumber(), Gpio.OUTPUT);
	Gpio.digitalWrite(properties.getRightMotorStepPinNumber(), false);
}
 
开发者ID:MHAVLOVICK,项目名称:Sketchy,代码行数:42,代码来源:RaspberryPIServoController.java


注:本文中的com.pi4j.wiringpi.Gpio.wiringPiSetupGpio方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。