本文整理汇总了Java中com.pi4j.wiringpi.Gpio.pwmSetClock方法的典型用法代码示例。如果您正苦于以下问题:Java Gpio.pwmSetClock方法的具体用法?Java Gpio.pwmSetClock怎么用?Java Gpio.pwmSetClock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.pi4j.wiringpi.Gpio
的用法示例。
在下文中一共展示了Gpio.pwmSetClock方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
示例2: setFrequency
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
public void setFrequency(double frequency) {
int pwmClockDivisor = (int) ((double)DEFAULT_RPI_PWM_CLOCK_FREQUENCY / (frequency * (double)MAX_PWM_LEVEL));
Gpio.pwmSetClock(pwmClockDivisor);
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, "Clock Divisor "+pwmClockDivisor+" DEFAULT_RPI_PWM_CLOCK_FREQUENCY "+DEFAULT_RPI_PWM_CLOCK_FREQUENCY);
}
}
示例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));
}
示例4: 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);
}
示例5: setPWMFreq
import com.pi4j.wiringpi.Gpio; //导入方法依赖的package包/类
/**
* Sets the PWM frequency, which determines how many full pulses per second are generated.
* <p>Depending on the selected mode (Raspberry Pi PWM pin or PCA9685), the maximum available frequency
* is different.</p>
* @param frequency the new PWM frequency.
*/
public void setPWMFreq(double frequency) {
Tools.debug("New PWM frequency: " + (int)frequency, Tools.Color.ANSI_RED);
if(selectedMode == PCA9685_MODE) {
pca9685.setPWMFreq((int)frequency);
} else if(selectedMode == RPI_PWM_PIN_MODE) {
// The clock divisor is the divisor to reach the target frequency.
// This value is stored in the corresponding PWM register, and used
// by the Raspberry Pi hardware to generate the PWM signal.
// Note: to get the current clockFrequencyPWM to multiply with this divisor,
// you can use SystemInfo.getClockFrequencyPWM().
int pwmClockDivisor = (int) (DEFAULT_RPI_PWM_CLOCK_FREQUENCY / (frequency * rangeGenerator));
Gpio.pwmSetClock(pwmClockDivisor);
}
}
示例6: 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);
}
示例7: 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);
}