make assignment 8.2 work

This commit is contained in:
2025-10-29 15:44:08 +01:00
parent 8ddada6531
commit a04efb87e5
3 changed files with 163 additions and 143 deletions

View File

@@ -10,10 +10,9 @@ use cortex_m_rt::entry;
use stm32f4xx_hal::{self as hal};
use crate::hal::{pac, prelude::*};
use cortex_m_semihosting::hprintln;
mod leds;
use crate::leds::{UpdateLeds, Leds};
use crate::leds::{Leds, ToggleLed};
mod state_machine;
use crate::state_machine::StateMachine;
@@ -25,11 +24,15 @@ fn main() -> ! {
) {
//GPIOD ophalen
let gpiod = dp.GPIOD.split();
//pd12 is pin type
let mut green = gpiod.pd12.into_push_pull_output();
let mut red = gpiod.pd14.into_push_pull_output();
let mut blue = gpiod.pd15.into_push_pull_output();
//led pinnen uphalen
let mut green_pin = &mut gpiod.pd12.into_push_pull_output();
let mut red_pin = &mut gpiod.pd14.into_push_pull_output();
let mut blue_pin = &mut gpiod.pd15.into_push_pull_output();
let mut green = ToggleLed::new(&mut green_pin).expect("faild to set green led");
let mut red = ToggleLed::new(&mut red_pin).expect("faild to set red led");
let mut blue = ToggleLed::new(&mut blue_pin).expect("faild to set blue led");
let mut leds = Leds::new(&mut red, &mut green, &mut blue);
//leds struct en state machine maken
let mut state_machine = StateMachine::new(&mut leds);
//Klok instellen
@@ -39,17 +42,9 @@ fn main() -> ! {
// Create a delay abstraction based on SysTick
let mut delay = cp.SYST.delay(&clocks);
let mut status:bool = false;
loop {
// On for 1s, off for 1s.
let _ = leds.red_toggle();
let _ = leds.green_toggle();
let _ = leds.blue_toggle();
status ^= true;
let _ = state_machine.second_passed();
delay.delay_ms(1000_u32);
//dit verschijnt in een van de open terminals in vscode
hprintln!("Led {:?}", status.then(|| "aan!").unwrap_or("uit!"));
}
}