本文整理汇总了Java中com.pi4j.wiringpi.SoftPwm.softPwmWrite方法的典型用法代码示例。如果您正苦于以下问题:Java SoftPwm.softPwmWrite方法的具体用法?Java SoftPwm.softPwmWrite怎么用?Java SoftPwm.softPwmWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.pi4j.wiringpi.SoftPwm
的用法示例。
在下文中一共展示了SoftPwm.softPwmWrite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.pi4j.wiringpi.SoftPwm; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
// initialize wiringPi library
com.pi4j.wiringpi.Gpio.wiringPiSetup();
// create soft-pwm pins (min=0 ; max=100)
SoftPwm.softPwmCreate(1, 0, 100);
// continuous loop
while (true) {
// fade LED to fully ON
for (int i = 0; i <= 100; i++) {
SoftPwm.softPwmWrite(1, i);
Thread.sleep(100);
}
// fade LED to fully OFF
for (int i = 100; i >= 0; i--) {
SoftPwm.softPwmWrite(1, i);
Thread.sleep(100);
}
}
// make sure to stop software PWM driver/thread if you done with it.
//SoftPwm.softPwmStop(1);
}
示例2: moveForward
import com.pi4j.wiringpi.SoftPwm; //导入方法依赖的package包/类
@Override
public synchronized void moveForward (int speed){
if (!forward){
SoftPwm.softPwmWrite( backwardPin.getAddress(), 0 );
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
;
}
}
SoftPwm.softPwmWrite( forwardPin.getAddress(), speed );
this.speed = speed;
forward = true;
}
示例3: moveBackward
import com.pi4j.wiringpi.SoftPwm; //导入方法依赖的package包/类
@Override
public synchronized void moveBackward (int speed){
if (forward){
SoftPwm.softPwmWrite( forwardPin.getAddress(), 0 );
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
;
}
}
SoftPwm.softPwmWrite( backwardPin.getAddress(), speed );
this.speed = speed;
forward = false;
}
示例4: main
import com.pi4j.wiringpi.SoftPwm; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
// initialize wiringPi library
com.pi4j.wiringpi.Gpio.wiringPiSetup();
// create soft-pwm pins (min=0 ; max=100)
SoftPwm.softPwmCreate(1, 0, 100);
// continuous loop
while (true) {
// fade LED to fully ON
for (int i = 0; i <= 100; i++) {
SoftPwm.softPwmWrite(1, i);
Thread.sleep(100);
}
// fade LED to fully OFF
for (int i = 100; i >= 0; i--) {
SoftPwm.softPwmWrite(1, i);
Thread.sleep(100);
}
}
}
示例5: stop
import com.pi4j.wiringpi.SoftPwm; //导入方法依赖的package包/类
@Override
public synchronized void stop(){
SoftPwm.softPwmWrite( forwardPin.getAddress(), 0 );
SoftPwm.softPwmWrite( backwardPin.getAddress(), 0 );
this.speed = 0;
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
;
}
}
示例6: setValue
import com.pi4j.wiringpi.SoftPwm; //导入方法依赖的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;
}
}
示例7: setValue
import com.pi4j.wiringpi.SoftPwm; //导入方法依赖的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;
}
}
示例8: testPWM
import com.pi4j.wiringpi.SoftPwm; //导入方法依赖的package包/类
public void testPWM() {
try {
// initialize wiringPi library
com.pi4j.wiringpi.Gpio.wiringPiSetup();
// create soft-pwm pins (min=0 ; max=100)
SoftPwm.softPwmCreate(1, 0, 100);
// continuous loop
while (true) {
// fade LED to fully ON
for (int i = 0; i <= 100; i++) {
SoftPwm.softPwmWrite(1, i);
Thread.sleep(100);
}
// fade LED to fully OFF
for (int i = 100; i >= 0; i--) {
SoftPwm.softPwmWrite(1, i);
Thread.sleep(100);
}
}
} catch (Exception e) {
}
}
示例9: penUp
import com.pi4j.wiringpi.SoftPwm; //导入方法依赖的package包/类
public synchronized void penUp(){
if (isPenDown){
SoftPwm.softPwmWrite(properties.getPenPinNumber(), properties.getPenUpPowerLevel());
Gpio.delayMicroseconds(properties.getPenUpPeriodInMilliseconds()*1000);
SoftPwm.softPwmWrite(properties.getPenPinNumber(), properties.getPenUpHoldPowerLevel());
isPenDown=false;
}
}
示例10: penDown
import com.pi4j.wiringpi.SoftPwm; //导入方法依赖的package包/类
public synchronized void penDown(){
if (!isPenDown){
SoftPwm.softPwmWrite(properties.getPenPinNumber(), 0); // off
Gpio.delayMicroseconds(properties.getPenDownPeriodInMilliseconds()*1000);
isPenDown=true;
}
}
示例11: tearDownPins
import com.pi4j.wiringpi.SoftPwm; //导入方法依赖的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
}
示例12: turnOffLedBeforeFinishSketch
import com.pi4j.wiringpi.SoftPwm; //导入方法依赖的package包/类
@Test
@Category(SlowTest.class)
public void turnOffLedBeforeFinishSketch() throws InterruptedException{
sketch.setup(NO_ARGS);
sketch.setSketchInterruption();
sketch.loop();
PowerMockito.verifyStatic(atLeast(1));
SoftPwm.softPwmWrite(LEDPINRED, 0);
PowerMockito.verifyStatic(atLeast(1));
SoftPwm.softPwmWrite(LEDPINGREEN, 0);
PowerMockito.verifyStatic(atLeast(1));
SoftPwm.softPwmWrite(LEDPINBLUE, 0);
}
示例13: testPWM
import com.pi4j.wiringpi.SoftPwm; //导入方法依赖的package包/类
public void testPWM() {
try {
// initialize wiringPi library
com.pi4j.wiringpi.Gpio.wiringPiSetup();
// create soft-pwm pins (min=0 ; max=100)
SoftPwm.softPwmCreate(1, 0, 100);
// continuous loop
while (true) {
// fade LED to fully ON
for (int i = 0; i <= 100; i++) {
SoftPwm.softPwmWrite(1, i);
Thread.sleep(100);
}
// fade LED to fully OFF
for (int i = 100; i >= 0; i--) {
SoftPwm.softPwmWrite(1, i);
Thread.sleep(100);
}
}
} catch (Exception e) {
}
}
示例14: main
import com.pi4j.wiringpi.SoftPwm; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
// get a handle to the GPIO controller
final GpioController gpio = GpioFactory.getInstance();
// init soft PWM pins
// softPwmCreate(int pin, int value, int range)
// the range is set like (min=0 ; max=100)
SoftPwm.softPwmCreate(MOTOR_1_PIN_A, 0, 100);
SoftPwm.softPwmCreate(MOTOR_1_PIN_B, 0, 100);
SoftPwm.softPwmCreate(MOTOR_2_PIN_A, 0, 100);
SoftPwm.softPwmCreate(MOTOR_2_PIN_B, 0, 100);
// init GPIO pins
final GpioPinDigitalOutput motor1pinE = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_06, "m1E");
final GpioPinDigitalOutput motor2pinE = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03, "m2E");
System.out.println("rotate motor 1 clockwise at 15% speed for 2 seconds");
motor1pinE.high();
SoftPwm.softPwmWrite(MOTOR_1_PIN_A, 15);
// wait 2 seconds
Thread.sleep(2000);
System.out.println("rotate motor 1 clockwise at 60% speed for 2 seconds");
SoftPwm.softPwmWrite(MOTOR_1_PIN_A, 60);
// wait 2 seconds
Thread.sleep(2000);
System.out.println("rotate motor 1 clockwise at full speed for 2 seconds");
SoftPwm.softPwmWrite(MOTOR_1_PIN_A, 100);
// wait 2 seconds
Thread.sleep(2000);
System.out.println("rotate motor 1 in oposite direction at 50% speed for 3 seconds");
SoftPwm.softPwmWrite(MOTOR_1_PIN_A, 0);
SoftPwm.softPwmWrite(MOTOR_1_PIN_B, 50);
// wait 3 seconds
Thread.sleep(3000);
// disable motor 1
SoftPwm.softPwmWrite(MOTOR_1_PIN_B, 0);
motor1pinE.low();
System.out.println("rotate motor 2 clockwise at 30% speed for 2 seconds");
motor2pinE.high();
SoftPwm.softPwmWrite(MOTOR_2_PIN_A, 30);
// wait 2 seconds
Thread.sleep(2000);
System.out.println("rotate motor 2 in oposite direction at 100% speed for 3 seconds");
SoftPwm.softPwmWrite(MOTOR_2_PIN_A, 0);
SoftPwm.softPwmWrite(MOTOR_2_PIN_B, 100);
// wait 3 seconds
Thread.sleep(3000);
// disable motor 2
SoftPwm.softPwmWrite(MOTOR_2_PIN_B, 0);
motor2pinE.low();
gpio.shutdown();
}
示例15: ledColorSet
import com.pi4j.wiringpi.SoftPwm; //导入方法依赖的package包/类
protected void ledColorSet(int colorA, int colorB) {
SoftPwm.softPwmWrite(LEDPINRED, colorA);
SoftPwm.softPwmWrite(LEDPINGREEN, colorB);
}