pub struct LCDController { /* private fields */ }Implementations§
Source§impl LCDController
impl LCDController
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>>
Sourcepub fn default() -> Result<LCDController, Box<dyn Error>>
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
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}Sourcepub fn reset_data_pins(&mut self)
pub fn reset_data_pins(&mut self)
Resets the data pin values to low
Sourcepub fn display_text(&mut self, text: &str, line: LcdLine)
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
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}Sourcepub fn clear_screen(&mut self)
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
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
impl Display for LCDController
Auto Trait Implementations§
impl Freeze for LCDController
impl !RefUnwindSafe for LCDController
impl Send for LCDController
impl Sync for LCDController
impl Unpin for LCDController
impl !UnwindSafe for LCDController
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