本文整理匯總了Java中com.google.android.things.pio.Pwm類的典型用法代碼示例。如果您正苦於以下問題:Java Pwm類的具體用法?Java Pwm怎麽用?Java Pwm使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Pwm類屬於com.google.android.things.pio包,在下文中一共展示了Pwm類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setPwmThrottle
import com.google.android.things.pio.Pwm; //導入依賴的package包/類
private void setPwmThrottle(Pwm pwm, int throttle) throws IOException {
if (throttle < POWER_MIN || throttle > POWER_MAX) {
throw new IllegalArgumentException("Throttle must be between 0 and 100. Throttle: " + throttle);
}
if (pwm == null) {
throw new IllegalStateException("PWM Device not open");
}
pwm.setPwmDutyCycle(throttle);
pwm.setEnabled(throttle != 0);
}
示例2: Speaker
import com.google.android.things.pio.Pwm; //導入依賴的package包/類
/**
* Create a Speaker connected to the given PWM pin name
*/
public Speaker(String pin) throws IOException {
PeripheralManagerService pioService = new PeripheralManagerService();
Pwm device = pioService.openPwm(pin);
try {
connect(device);
} catch (IOException|RuntimeException e) {
try {
close();
} catch (IOException|RuntimeException ignored) {
}
throw e;
}
}
示例3: Servo
import com.google.android.things.pio.Pwm; //導入依賴的package包/類
/**
* Create a new Servo that connects to the named pin and uses the specified frequency
*
* @param pin the PWM pin name
* @param frequencyHz the frequency in Hertz
* @throws IOException
*/
public Servo(String pin, double frequencyHz) throws IOException {
PeripheralManagerService pioService = new PeripheralManagerService();
Pwm device = pioService.openPwm(pin);
try {
connect(device, frequencyHz);
} catch (IOException | RuntimeException e) {
try {
close();
} catch (IOException | RuntimeException ignored) {
}
throw e;
}
}
示例4: connect
import com.google.android.things.pio.Pwm; //導入依賴的package包/類
/**
* Create a new Servo that connects to the given PWM device and uses the specified frequency
*
* @param device the PWM device
* @param frequencyHz the frequency in Hertz
* @throws IOException
*/
@VisibleForTesting
/*package*/ Servo(Pwm device, double frequencyHz) throws IOException {
try {
connect(device, frequencyHz);
} catch (IOException | RuntimeException e) {
try {
close();
} catch (IOException | RuntimeException ignored) {
}
throw e;
}
}
示例5: connect
import com.google.android.things.pio.Pwm; //導入依賴的package包/類
/**
* Create a Speaker from a {@link Pwm} device
*/
@VisibleForTesting
/*package*/ Speaker(Pwm device) throws IOException {
connect(device);
}
示例6: this
import com.google.android.things.pio.Pwm; //導入依賴的package包/類
/**
* Create a new Servo that connects to the given PWM device
*
* @param device the PWM device
* @throws IOException
*/
@VisibleForTesting
/*package*/ Servo(Pwm device) throws IOException {
this(device, DEFAULT_FREQUENCY_HZ);
}