pub struct Joystick<I2C> { /* private fields */ }Expand description
Driver for the Modulino Joystick module.
The joystick reports X and Y values in the range -128 to 127, where (0, 0) is the center position.
§Example
ⓘ
use modulino::Joystick;
let mut joystick = Joystick::new(i2c)?;
loop {
joystick.update()?;
let x = joystick.x();
let y = joystick.y();
if joystick.button_pressed() {
println!("Button pressed at position ({}, {})", x, y);
}
}Implementations§
Source§impl<I2C, E> Joystick<I2C>where
I2C: I2c<Error = E>,
impl<I2C, E> Joystick<I2C>where
I2C: I2c<Error = E>,
Sourcepub const DEFAULT_DEADZONE: u8 = 10
pub const DEFAULT_DEADZONE: u8 = 10
Default deadzone threshold.
Sourcepub fn new(i2c: I2C) -> Result<Self, E>
pub fn new(i2c: I2C) -> Result<Self, E>
Create a new Joystick instance with the default address.
Sourcepub fn new_with_address(i2c: I2C, address: u8) -> Result<Self, E>
pub fn new_with_address(i2c: I2C, address: u8) -> Result<Self, E>
Create a new Joystick instance with a custom address.
Sourcepub fn update(&mut self) -> Result<bool, E>
pub fn update(&mut self) -> Result<bool, E>
Update the joystick state.
This should be called periodically to read the latest values.
Returns true if the state has changed.
Check if the button is pressed.
Sourcepub fn set_deadzone(&mut self, deadzone: u8)
pub fn set_deadzone(&mut self, deadzone: u8)
Set the deadzone threshold.
Values within this distance from center (0, 0) will be reported as 0.
Sourcepub fn is_centered(&self) -> bool
pub fn is_centered(&self) -> bool
Check if the joystick is in the center position (within deadzone).
Auto Trait Implementations§
impl<I2C> Freeze for Joystick<I2C>where
I2C: Freeze,
impl<I2C> RefUnwindSafe for Joystick<I2C>where
I2C: RefUnwindSafe,
impl<I2C> Send for Joystick<I2C>where
I2C: Send,
impl<I2C> Sync for Joystick<I2C>where
I2C: Sync,
impl<I2C> Unpin for Joystick<I2C>where
I2C: Unpin,
impl<I2C> UnwindSafe for Joystick<I2C>where
I2C: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more