Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Playing with shift registers with Rust + ARMv7 + GPIO
extern crate sysfs_gpio;
use sysfs_gpio::{Direction,Pin};
use std::time::Duration;
use std::thread::sleep;
fn main() {
let data_pin = Pin::new(18); // SER #14
let latch_pin = Pin::new(23); // RCLK #12
let clock_pin = Pin::new(24); // SRCLK #11
let mut serial_value = 0;
data_pin.export().unwrap();
latch_pin.export().unwrap();
clock_pin.export().unwrap();
// Let's give udev rules the time to get applied
sleep(Duration::from_millis(1000));
data_pin.set_direction(Direction::Low).unwrap();
latch_pin.set_direction(Direction::Low).unwrap();
clock_pin.set_direction(Direction::Low).unwrap();
for _ in 0..16 {
serial_value = 1;
println!("{}", serial_value);
latch_pin.set_value(0).unwrap();
data_pin.set_value(serial_value).unwrap();
clock_pin.set_value(1).unwrap();
clock_pin.set_value(0).unwrap();
latch_pin.set_value(1).unwrap();
sleep(Duration::from_millis(500));
}
for _ in 0..16 {
serial_value = 0;
println!("{}", serial_value);
latch_pin.set_value(0).unwrap();
data_pin.set_value(serial_value).unwrap();
clock_pin.set_value(1).unwrap();
clock_pin.set_value(0).unwrap();
latch_pin.set_value(1).unwrap();
sleep(Duration::from_millis(500));
}
data_pin.unexport().unwrap();
latch_pin.unexport().unwrap();
clock_pin.unexport().unwrap();
println!("Done.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.