Struct Arduino

Source
pub struct Arduino(/* private fields */);
Expand description

A handle on an Arduino, for communicating with it via the Firmata protocol.

Implementations§

Source§

impl Arduino

Source

pub fn new() -> Result<Arduino, Error>

Creates an Arduino object from the single currently connected Arduino device.

§Errors

This function calls arduino::cli::query, and will pass along any errors produced by it.

Examples found in repository?
examples/blink.rs (line 10)
9fn main() {
10    let mut arduino = Arduino::new().unwrap();
11    let pin_10 = arduino::Pin::new(10);
12
13    arduino.set_pin_mode(pin_10, arduino::pin::Mode::Output);
14    arduino.digital_write(pin_10, arduino::pin::State::High);
15
16    sleep(Duration::from_secs(1));
17
18    arduino.digital_write(pin_10, arduino::pin::State::Low);
19}
Source

pub fn digital_write(&mut self, pin: Pin, state: State)

Writes the given pin state to the given pin of the Arduino.

Examples found in repository?
examples/blink.rs (line 14)
9fn main() {
10    let mut arduino = Arduino::new().unwrap();
11    let pin_10 = arduino::Pin::new(10);
12
13    arduino.set_pin_mode(pin_10, arduino::pin::Mode::Output);
14    arduino.digital_write(pin_10, arduino::pin::State::High);
15
16    sleep(Duration::from_secs(1));
17
18    arduino.digital_write(pin_10, arduino::pin::State::Low);
19}
Source

pub fn analog_write(&mut self, pin: Pin, level: Level)

Writes the given pin level to the given pin of the Arduino.

Source

pub fn set_pin_mode(&mut self, pin: Pin, mode: Mode)

Set the given pin of the Arduino to the given mode.

Examples found in repository?
examples/blink.rs (line 13)
9fn main() {
10    let mut arduino = Arduino::new().unwrap();
11    let pin_10 = arduino::Pin::new(10);
12
13    arduino.set_pin_mode(pin_10, arduino::pin::Mode::Output);
14    arduino.digital_write(pin_10, arduino::pin::State::High);
15
16    sleep(Duration::from_secs(1));
17
18    arduino.digital_write(pin_10, arduino::pin::State::Low);
19}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.