Chanc.ee

11 Jun 2021

Rust and LEDs

After struggling with setting up a Vacuum Florescent Display via I2C for a while I ended up getting about as low level as possible with wires and LEDs to solve the problem. Along the way I needed the most foolproof GPIO level control I could create.

extern crate sysfs_gpio;
use sysfs_gpio::{Direction, Pin};


fn led_fun() {

   let led_sca = Pin::new(475); // number depends on chip, etc.
   led_sca.set_direction(Direction::Out);
   led_sca.export();
   led_sca.set_value(1);

   let led_sck = Pin::new(474);
   led_sck.set_direction(Direction::Out);
   led_sck.export();
   led_sck.set_value(1);

}

fn main() {
    led_fun();
}

After a cargo run you'll need to use sudo to execute the binary i.e. sudo ./target/debug/led-fun-binary to avoid a permission denied error when you attempt to access the GPIO bus.

I really thought I'd hate Rust at first with it's...well, just look at it. It's not pretty. It's damn unpretty - but after a while you can see the elegance in the sparsity.

This post has not been webmention'd yet.

Chancee is a designer who codes from London Town.

They have worked for the likes of Nike, Vodafone, Sky, Disney and Pearsons. Won awards from Promax, BAFTAs, the Appys and The Drum. Spoken at The Waldorf and Southampton University - despite swearing like a sailor. Available for hire to draw pretty curves and code clever things.