LCDController

Struct LCDController 

Source
pub struct LCDController { /* private fields */ }

Implementations§

Source§

impl LCDController

Source

pub fn new( lcd_rs: u8, lcd_e: u8, lcd_d4: u8, lcd_d5: u8, lcd_d6: u8, lcd_d7: u8, ) -> Result<LCDController, Box<dyn Error>>

Source

pub fn default() -> Result<LCDController, Box<dyn Error>>

IMPORTANT!!! READ BEFORE USING DEFAULT!!!

the default pin configuration may not work for your case and may damage the device if inproperly wired, make sure your read the guide on connecting the raspberry pi in the README, this will work with that specific wiring configuration

Examples found in repository?
examples/basic_usage.rs (line 15)
12fn main() -> Result<(), Box<dyn Error>> {
13    // Create an LCD controller instance
14    // You can use the default pins specified in the README or specify your own pin configuration with LCDController::new()
15    let mut controller = LCDController::default().unwrap();
16
17    // Print LCD controller information
18    println!("{controller}");
19
20    for _ in 0..5 {
21        // Display text on the LCD
22        controller.display_text("Hello World!", LcdLine::Line1);
23        sleep(3);
24
25        controller.display_text("Hello Rustaceans", LcdLine::Line2);
26        sleep(5);
27
28        controller.clear_screen();
29        sleep(1);
30    }
31
32    Ok(())
33}
More examples
Hide additional examples
examples/advanced_usage.rs (line 16)
14fn main() -> Result<(), Box<dyn Error>> {
15    // Create an LCD controller instance and wrap it in a mutex
16    let shared_controller = Arc::new(Mutex::new(LCDController::default()?));
17
18    // Create a channel for communication between main thread and LCD thread
19    let (lcd_tx, lcd_rx) = mpsc::channel();
20
21    // Clone the Arc to send to the LCD thread
22    let shared_controller_clone = shared_controller.clone();
23
24    // Spawn a new thread for handling the LCD
25    let lcd_thread = thread::spawn(move || {
26        for command in lcd_rx {
27            match command {
28                LCDCommand::DisplayText(text, line) => {
29                    let mut controller = shared_controller_clone.lock().unwrap();
30                    controller.display_text(&text, line);
31                }
32                LCDCommand::ClearScreen => {
33                    let mut controller = shared_controller_clone.lock().unwrap();
34                    controller.clear_screen();
35                }
36                LCDCommand::Quit => {
37                    // Cleanup and exit the thread
38                    break;
39                }
40            }
41        }
42    });
43
44    // Continue with the main thread logic here
45    // ...
46
47    // Example: Send commands to the LCD thread
48    lcd_tx.send(LCDCommand::DisplayText(
49        "Hello World!".to_string(),
50        LcdLine::Line1,
51    ))?;
52    thread::sleep(Duration::new(3, 0));
53    lcd_tx.send(LCDCommand::DisplayText(
54        "Hello Rustaceans".to_string(),
55        LcdLine::Line2,
56    ))?;
57    thread::sleep(Duration::new(5, 0));
58
59    // Send a command to clear the screen
60    lcd_tx.send(LCDCommand::ClearScreen)?;
61
62    // Signal the LCD thread to quit
63    lcd_tx.send(LCDCommand::Quit)?;
64
65    // Wait for the LCD thread to finish before exiting
66    lcd_thread.join().unwrap();
67
68    Ok(())
69}
Source

pub fn reset_data_pins(&mut self)

Resets the data pin values to low

Source

pub fn reset(&mut self)

Resets all the pins values to low and clear the display

Source

pub fn send(&mut self, bits: u8, mode: LcdMode)

Send a command or character to the display

Source

pub fn display_text(&mut self, text: &str, line: LcdLine)

Display text on the LCD display

Panics: if text length is > 16 (LCD_CHARS) Make sure to handle the incorect text length yourself, this is done to prevent unexpected behaviour.

Examples found in repository?
examples/basic_usage.rs (line 22)
12fn main() -> Result<(), Box<dyn Error>> {
13    // Create an LCD controller instance
14    // You can use the default pins specified in the README or specify your own pin configuration with LCDController::new()
15    let mut controller = LCDController::default().unwrap();
16
17    // Print LCD controller information
18    println!("{controller}");
19
20    for _ in 0..5 {
21        // Display text on the LCD
22        controller.display_text("Hello World!", LcdLine::Line1);
23        sleep(3);
24
25        controller.display_text("Hello Rustaceans", LcdLine::Line2);
26        sleep(5);
27
28        controller.clear_screen();
29        sleep(1);
30    }
31
32    Ok(())
33}
More examples
Hide additional examples
examples/advanced_usage.rs (line 30)
14fn main() -> Result<(), Box<dyn Error>> {
15    // Create an LCD controller instance and wrap it in a mutex
16    let shared_controller = Arc::new(Mutex::new(LCDController::default()?));
17
18    // Create a channel for communication between main thread and LCD thread
19    let (lcd_tx, lcd_rx) = mpsc::channel();
20
21    // Clone the Arc to send to the LCD thread
22    let shared_controller_clone = shared_controller.clone();
23
24    // Spawn a new thread for handling the LCD
25    let lcd_thread = thread::spawn(move || {
26        for command in lcd_rx {
27            match command {
28                LCDCommand::DisplayText(text, line) => {
29                    let mut controller = shared_controller_clone.lock().unwrap();
30                    controller.display_text(&text, line);
31                }
32                LCDCommand::ClearScreen => {
33                    let mut controller = shared_controller_clone.lock().unwrap();
34                    controller.clear_screen();
35                }
36                LCDCommand::Quit => {
37                    // Cleanup and exit the thread
38                    break;
39                }
40            }
41        }
42    });
43
44    // Continue with the main thread logic here
45    // ...
46
47    // Example: Send commands to the LCD thread
48    lcd_tx.send(LCDCommand::DisplayText(
49        "Hello World!".to_string(),
50        LcdLine::Line1,
51    ))?;
52    thread::sleep(Duration::new(3, 0));
53    lcd_tx.send(LCDCommand::DisplayText(
54        "Hello Rustaceans".to_string(),
55        LcdLine::Line2,
56    ))?;
57    thread::sleep(Duration::new(5, 0));
58
59    // Send a command to clear the screen
60    lcd_tx.send(LCDCommand::ClearScreen)?;
61
62    // Signal the LCD thread to quit
63    lcd_tx.send(LCDCommand::Quit)?;
64
65    // Wait for the LCD thread to finish before exiting
66    lcd_thread.join().unwrap();
67
68    Ok(())
69}
Source

pub fn clear_screen(&mut self)

Clear the screen of the LCD display

Examples found in repository?
examples/basic_usage.rs (line 28)
12fn main() -> Result<(), Box<dyn Error>> {
13    // Create an LCD controller instance
14    // You can use the default pins specified in the README or specify your own pin configuration with LCDController::new()
15    let mut controller = LCDController::default().unwrap();
16
17    // Print LCD controller information
18    println!("{controller}");
19
20    for _ in 0..5 {
21        // Display text on the LCD
22        controller.display_text("Hello World!", LcdLine::Line1);
23        sleep(3);
24
25        controller.display_text("Hello Rustaceans", LcdLine::Line2);
26        sleep(5);
27
28        controller.clear_screen();
29        sleep(1);
30    }
31
32    Ok(())
33}
More examples
Hide additional examples
examples/advanced_usage.rs (line 34)
14fn main() -> Result<(), Box<dyn Error>> {
15    // Create an LCD controller instance and wrap it in a mutex
16    let shared_controller = Arc::new(Mutex::new(LCDController::default()?));
17
18    // Create a channel for communication between main thread and LCD thread
19    let (lcd_tx, lcd_rx) = mpsc::channel();
20
21    // Clone the Arc to send to the LCD thread
22    let shared_controller_clone = shared_controller.clone();
23
24    // Spawn a new thread for handling the LCD
25    let lcd_thread = thread::spawn(move || {
26        for command in lcd_rx {
27            match command {
28                LCDCommand::DisplayText(text, line) => {
29                    let mut controller = shared_controller_clone.lock().unwrap();
30                    controller.display_text(&text, line);
31                }
32                LCDCommand::ClearScreen => {
33                    let mut controller = shared_controller_clone.lock().unwrap();
34                    controller.clear_screen();
35                }
36                LCDCommand::Quit => {
37                    // Cleanup and exit the thread
38                    break;
39                }
40            }
41        }
42    });
43
44    // Continue with the main thread logic here
45    // ...
46
47    // Example: Send commands to the LCD thread
48    lcd_tx.send(LCDCommand::DisplayText(
49        "Hello World!".to_string(),
50        LcdLine::Line1,
51    ))?;
52    thread::sleep(Duration::new(3, 0));
53    lcd_tx.send(LCDCommand::DisplayText(
54        "Hello Rustaceans".to_string(),
55        LcdLine::Line2,
56    ))?;
57    thread::sleep(Duration::new(5, 0));
58
59    // Send a command to clear the screen
60    lcd_tx.send(LCDCommand::ClearScreen)?;
61
62    // Signal the LCD thread to quit
63    lcd_tx.send(LCDCommand::Quit)?;
64
65    // Wait for the LCD thread to finish before exiting
66    lcd_thread.join().unwrap();
67
68    Ok(())
69}

Trait Implementations§

Source§

impl Display for LCDController

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for LCDController

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.