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


Java Gpio.pwmWrite方法代码示例

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


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

示例1: 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

示例2: setPWM

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
/**
 * Sets for each full pulse of the PWM signal, the tick where the signal turns off (low).
 * 
 * <p>The rangeGenerator is used to define the range of values that the off tick can take.
 * As an example, a rangeGenerator of 20000 and an off value of 5000 means that
 * each PWM full pulse is composed of 25% high signal, followed by 75% of low signal.</p>
 * 
 * <p><b>! Attention !</b> when using the PCA9685, the maximum rangeGenerator is 4096 (maximum 12-bits value).</p>
 * 
 * <p>If you use a higher value for the off than for the rangeGenerator, we will set
 * the off value to the rangeGenerator value.</p>
 * 
 * <p>Note that an off value of zero will stop the PWM signal.</p>
 * @param off the tick where the signal turns off (low). 0 to stop the PWM signal.
 * @see PWMComponent#setPWM(int, long)
 */
public void setPWM(int off) {
    off = Math.max(off, 0);
    off = Math.min(off, rangeGenerator);
    
    if(stop)
        off = 0;
    
    if(selectedMode == PCA9685_MODE) {
        // with the PCA9685, a pulse is composed of 4096 ticks (12bits).
        // the range of values for the on, off ticks, must then be adapted to this 0..4096 range.
        off = (int)(((double)off / (double)rangeGenerator) * PCA9685_PULSE_TICKS);
        
        pca9685.setPWM(channel, 0, off);
    } else if(selectedMode == RPI_PWM_PIN_MODE) {
        Gpio.pwmWrite(pin.getPin().getWiringPiNb(), off);
    }
}
 
开发者ID:Raspoid,项目名称:raspoid,代码行数:34,代码来源:PWMComponent.java

示例3: setBrightness

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public void setBrightness(float newval) {
		if (newval >= 0 && newval <= 1) {
			brightness = newval;
			if (StaticVars.debugOn == false) {
				Gpio.pwmWrite(12, (int) Math.ceil(brightness * 1024f));
//				SoftPwm.softPwmWrite(12, (int)(Math.ceil(brightness*10)));
			} else {
				Utils.out.println(1, "Brightness: " + newval);
			}
		}
	}
 
开发者ID:XDrake99,项目名称:WarpPI,代码行数:12,代码来源:DisplayManager.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: setValue

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
@Override
public void setValue(float value) throws RuntimeIOException {
	this.value = value;
	int dc = (int) Math.floor(value * range);
	switch (pwmType) {
	case HARDWARE:
		Logger.info("setValue({}), range={}, dc={}", Float.valueOf(value), Integer.valueOf(range), Integer.valueOf(dc));
		Gpio.pwmWrite(gpio, dc);
		break;
	case SOFTWARE:
	default:
		SoftPwm.softPwmWrite(gpio, dc);
		break;
	}
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:16,代码来源:WiringPiPwmOutputDevice.java

示例6: 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

示例7: setValue

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
@Override
public void setValue(float value) throws RuntimeIOException {
	this.value = value;
	switch (pwmType) {
	case HARDWARE:
		Logger.info("Pi4j Hardware PWM write " + (Math.round(value * range)));
		Gpio.pwmWrite(gpio, Math.round(value * range));
		break;
	case SOFTWARE:
		SoftPwm.softPwmWrite(gpio, Math.round(value * range));
		break;
	}
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:14,代码来源:Pi4jPwmOutputDevice.java

示例8: setValue

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
/**
 * Sets the value sent to the PWM pin.
 * @param value the new value, in the previously set min..max range.
 */
public void setValue(int value) {
    if(value < minValue)
        value = minValue;
    else if(value > maxValue)
        value = maxValue;
    Gpio.pwmWrite(pinNumber, value);
}
 
开发者ID:Raspoid,项目名称:raspoid,代码行数:12,代码来源:ServoMotorCallibration.java

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

示例10: pulse

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
/**
 * Sends an IR pulse for a duration of micros microseconds.
 * <p>Note: this method isn't placed in the parent PWMComponent, because it's deprecated to use a Gpio.delayMicroseconds.
 * Indeed, since the system is not in realtime executions, we can't get any guarantee regarding the microseconds delays.</p>
 * @param micros
 */
private void pulse(long micros) {
    Gpio.pwmWrite(pinNumber, 50); // 50%
    Gpio.delayMicroseconds(micros);
    Gpio.pwmWrite(pinNumber, 0);
}
 
开发者ID:Raspoid,项目名称:raspoid,代码行数:12,代码来源:IRTransmitter.java

示例11: stop

import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
/**
 * Stop sending orders to the servo motor.
 * <p>It tells the motor to turn itself off and wait for more instructions.</p>
 */
public void stop() {
    Gpio.pwmWrite(pinNumber, 0);
}
 
开发者ID:Raspoid,项目名称:raspoid,代码行数:8,代码来源:ServoMotorCallibration.java


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