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


Java Gpio.pwmSetMode方法代码示例

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


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

示例1: IRSend

import com.pi4j.wiringpi.Gpio; //导入方法依赖的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");
    }
}
 
开发者ID:gustavohbf,项目名称:robotoy,代码行数:19,代码来源:IRSend.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: setHardwarePwmFrequency

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
private void setHardwarePwmFrequency(int pwmFrequency) {
	// TODO Validate the requested PWM frequency
	hardwarePwmRange = DEFAULT_HARDWARE_PWM_RANGE;
	Gpio.pwmSetRange(hardwarePwmRange);
	int divisor = PI_PWM_CLOCK_BASE_FREQUENCY / hardwarePwmRange / pwmFrequency;
	Gpio.pwmSetClock(divisor);
	Gpio.pwmSetMode(Gpio.PWM_MODE_MS);
	this.boardPwmFrequency = pwmFrequency;
	Logger.info("setHardwarePwmFrequency({}) - range={}, divisor={}",
			Integer.valueOf(pwmFrequency), Integer.valueOf(hardwarePwmRange), Integer.valueOf(divisor));
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:12,代码来源:WiringPiDeviceFactory.java

示例4: WiringPiPwmOutputDevice

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
WiringPiPwmOutputDevice(String key, DeviceFactoryInterface deviceFactory, PwmType pwmType,
		int range, int gpio, float initialValue) throws RuntimeIOException {
	super(key, deviceFactory);
	
	this.pwmType = pwmType;
	this.gpio = gpio;
	this.value = initialValue;
	this.range = range;
	
	switch (pwmType) {
	case HARDWARE:
		if (GpioUtil.isExported(gpio)) {
			GpioUtil.setDirection(gpio, GpioUtil.DIRECTION_OUT);
		} else {
			GpioUtil.export(gpio, GpioUtil.DIRECTION_OUT);
		}
		Gpio.pinMode(gpio, Gpio.PWM_OUTPUT);
		// Have to call this after setting the pin mode! Yuck
		Gpio.pwmSetMode(Gpio.PWM_MODE_MS);
		Gpio.pwmWrite(gpio, Math.round(initialValue * range));
		break;
	case SOFTWARE:
		int status = SoftPwm.softPwmCreate(gpio, Math.round(initialValue * range), range);
		if (status != 0) {
			throw new RuntimeIOException("Error setting up software controlled PWM GPIO on BCM pin " +
					gpio + ", status=" + status);
		}
		break;
	}
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:31,代码来源:WiringPiPwmOutputDevice.java

示例5: Pi4jPwmOutputDevice

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
Pi4jPwmOutputDevice(String key, DeviceFactoryInterface deviceFactory, GpioController gpioController,
		PwmType pwmType, int gpio, float initialValue, int range) throws RuntimeIOException {
	super(key, deviceFactory);
	
	this.pwmType = pwmType;
	this.gpio = gpio;
	this.value = initialValue;
	this.range = range;
	
	//pin = RaspiBcmPin.getPinByAddress(gpio);
	//pin.getSupportedPinModes().contains(PinMode.PWM_OUTPUT);
	
	switch (pwmType) {
	case HARDWARE:
		//pwmOutputPin = gpioController.provisionPwmOutputPin(pin, "PWM output for BCM GPIO " + gpio,
		//		Math.round(value * range));
		Gpio.pinMode(gpio, Gpio.PWM_OUTPUT);
		// Have to call this after setting the pin mode! Yuck
		Gpio.pwmSetMode(Gpio.PWM_MODE_MS);
		Gpio.pwmWrite(gpio, Math.round(initialValue * range));
		break;
	case SOFTWARE:
		//pwmOutputPin = gpioController.provisionSoftPwmOutputPin(
		//		pin, "PWM output for BCM GPIO " + gpio, Math.round(initialValue * range));
		int status = SoftPwm.softPwmCreate(gpio, Math.round(initialValue * range), range);
		if (status != 0) {
			throw new RuntimeIOException("Error setting up software controlled PWM GPIO on BCM pin " +
					gpio + ", status=" + status);
		}
	}
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:32,代码来源:Pi4jPwmOutputDevice.java

示例6: 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);
}
 
开发者ID:Raspoid,项目名称:raspoid,代码行数:20,代码来源:ServoMotorCallibration.java

示例7: 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);}));
}
 
开发者ID:Raspoid,项目名称:raspoid,代码行数:25,代码来源:PWMComponent.java

示例8: Motor

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public Motor(Pin pwm, Pin direction, Pin enable) {
	GpioController gpio = GpioFactory.getInstance();

	Gpio.pwmSetMode(PWM_MODE_MS);
	Gpio.pwmSetRange(MAX_SPEED);
	Gpio.pwmSetClock(2);

	pwmPin = gpio.provisionPwmOutputPin(pwm, "pwm");
	pwmPin.setPwmRange(MAX_SPEED);

	directionPin = gpio.provisionDigitalOutputPin(direction, "direction");
	enablePin = gpio.provisionDigitalOutputPin(enable, "enable", PinState.LOW);
}
 
开发者ID:gaelblondelle,项目名称:PSysRoverInitialContrib,代码行数:14,代码来源:Motor.java

示例9: setupGpioForMovement

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
protected void setupGpioForMovement() {
	// Motor direction pins
	Gpio.pinMode(5, Gpio.OUTPUT);
	Gpio.pinMode(6, Gpio.OUTPUT);

	Gpio.pinMode(12, Gpio.PWM_OUTPUT);
	Gpio.pinMode(13, Gpio.PWM_OUTPUT);
	Gpio.pwmSetMode(Gpio.PWM_MODE_MS);
	Gpio.pwmSetRange(MAX_SPEED);
	Gpio.pwmSetClock(CLOCK_DIVISOR);
}
 
开发者ID:iproduct,项目名称:course-social-robotics,代码行数:12,代码来源:MovementCommandSubscriber.java


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