Multiplexing

Multiplex the rows of the matrix


# #![allow(unused_variables)]
#fn main() {
/// Display 3x9 matrix image for a given duration.
pub fn display_pre(&mut self, delay: &mut Delay, led_matrix: [[u8; 9]; 3], duration_ms: u32) {
    // TODO
    // These need to be populated with PINs, e.g.:
    let rows = [PIN; 3];
    let cols = [PIN; 9];
    // Set refresh rate.
    let delay_ms = 2;
    // Calculate number of loops.
    let loops = duration_ms / (rows.len() as u32 * delay_ms);
    for _ in 0..loops {
        for (row_line, led_matrix_row) in rows.iter_mut().zip(led_matrix.iter()) {
            // Set the row high.
            row_line.set_high();
            // Set the correct pins low (on)
            // This could lead to very small differences in execution time,
            // but this is not worth correcting for, as it is << 2ms.
            for (col_line, led_matrix_val) in cols.iter_mut().zip(led_matrix_row.iter()) {
                // We ignore any brightness setting, just use 0 and 1.
                if *led_matrix_val > 0 {
                    col_line.set_low();
                }
            }
            delay.delay_ms(delay_ms);
            // It is not worth the logic to check which pins need resetting,
            // so set all the pins back high.
            for col_line in &mut cols {
                col_line.set_high();
            }
            // Set the row back low.
            row_line.set_low();
        }
    }
}
#}