Struct libbeaglebone::pwm::PWM [] [src]

pub struct PWM { /* fields omitted */ }

Represents a PWM device.

Methods

impl PWM
[src]

Creates a new PWM object.

Note: you will need to configure the selected pin as a PWM output prior to use using the config-pin utility. For example, config-pin P9.21 pwm. See the examples/ directory for more help.

Examples

use libbeaglebone::pwm::PWM;

// Create a new PWM device using PWM chip 0 and PWM 0.
let mut pwm = PWM::new(0,0);

Exports the PWM.

Examples

use libbeaglebone::enums::DeviceState;
use libbeaglebone::pwm::PWM;

// Create a new PWM device using PWM chip 0 and PWM 0.
let mut pwm = PWM::new(0,0);

// Export the PWM.
pwm.set_export(DeviceState::Exported).unwrap();

Sets the period of the PWM in nanoseconds.

Examples

use libbeaglebone::enums::DeviceState;
use libbeaglebone::pwm::PWM;

// Create a new PWM device using PWM chip 0 and PWM 0.
let mut pwm = PWM::new(0,0);

// Export the PWM.
pwm.set_export(DeviceState::Exported).unwrap();

// Make the period 500,000ns.
pwm.set_period(500_000).unwrap();

Sets the state (enabled or disabled) of the PWM.

Examples

use libbeaglebone::enums::DeviceState;
use libbeaglebone::pwm::{PWM, PWMState};

// Create a new PWM device using PWM chip 0 and PWM 0.
let mut pwm = PWM::new(0,0);

// Export the PWM.
pwm.set_export(DeviceState::Exported).unwrap();

// Make the period 500,000ns.
pwm.set_period(500_000).unwrap();

// Turn the PWM on
pwm.set_state(PWMState::Enabled).unwrap();

Sets the duty cycle of the PWM as a percentage of the period.

Examples

use libbeaglebone::enums::DeviceState;
use libbeaglebone::pwm::{PWM, PWMState};

// Create a new PWM device using PWM chip 0 and PWM 0.
let mut pwm = PWM::new(0,0);

// Export the PWM.
pwm.set_export(DeviceState::Exported).unwrap();

// Make the period 500,000ns.
pwm.set_period(500_000).unwrap();

// Turn the PWM on.
pwm.set_state(PWMState::Enabled).unwrap();

// Set the duty cycle to 50% (250,000ns).
pwm.write(50.0).unwrap();

Sets the duty cycle of the PWM in nanoseconds.

Examples

use libbeaglebone::enums::DeviceState;
use libbeaglebone::pwm::{PWM, PWMState};

// Create a new PWM device using PWM chip 0 and PWM 0.
let mut pwm = PWM::new(0,0);

// Export the PWM.
pwm.set_export(DeviceState::Exported).unwrap();

// Make the period 500,000ns.
pwm.set_period(500_000).unwrap();

// Turn the PWM on.
pwm.set_state(PWMState::Enabled).unwrap();

// Set the duty cycle to 250,000ns.
pwm.set_duty_cycle(250_000).unwrap();

Trait Implementations

impl Debug for PWM
[src]

Formats the value using the given formatter.