feat: changed the pins

This commit is contained in:
2026-06-26 18:54:00 +02:00
parent 1848a32631
commit 422fb2a47a
3 changed files with 47 additions and 45 deletions
+29 -29
View File
@@ -12,57 +12,57 @@ use crate::{
pub struct TrafficController {
pub phase_index: usize,
pub phase_start: u64,
pub main_traffic_light: TrafficLight<Gpio0, Gpio1, Gpio2>,
pub north_traffic_light: TrafficLight<Gpio3, Gpio4, Gpio5>,
pub south_traffic_light: TrafficLight<Gpio6, Gpio7, Gpio8>,
pub pedestrian_light: PedestrianLight<Gpio9, Gpio10>,
pub button: Pin<Gpio11, FunctionSio<SioInput>, PullUp>,
pub main_traffic_light: TrafficLight<Gpio2, Gpio3, Gpio4>,
pub north_traffic_light: TrafficLight<Gpio5, Gpio6, Gpio7>,
pub south_traffic_light: TrafficLight<Gpio8, Gpio9, Gpio10>,
pub pedestrian_light: PedestrianLight<Gpio11, Gpio12>,
pub button: Pin<Gpio13, FunctionSio<SioInput>, PullUp>,
pub button_state: bool,
}
impl TrafficController {
pub fn new(
gpio0: Pin<Gpio0, FunctionNull, PullDown>,
gpio1: Pin<Gpio1, FunctionNull, PullDown>,
gpio2: Pin<Gpio2, FunctionNull, PullDown>,
gpio3: Pin<Gpio3, FunctionNull, PullDown>,
gpio4: Pin<Gpio4, FunctionNull, PullDown>,
gpio5: Pin<Gpio5, FunctionNull, PullDown>,
gpio6: Pin<Gpio6, FunctionNull, PullDown>,
gpio7: Pin<Gpio7, FunctionNull, PullDown>,
gpio8: Pin<Gpio8, FunctionNull, PullDown>,
gpio9: Pin<Gpio9, FunctionNull, PullDown>,
gpio10: Pin<Gpio10, FunctionNull, PullDown>,
gpio11: Pin<Gpio11, FunctionNull, PullDown>,
main_red: Pin<Gpio2, FunctionNull, PullDown>,
main_yellow: Pin<Gpio3, FunctionNull, PullDown>,
main_green: Pin<Gpio4, FunctionNull, PullDown>,
north_red: Pin<Gpio5, FunctionNull, PullDown>,
north_yellow: Pin<Gpio6, FunctionNull, PullDown>,
north_green: Pin<Gpio7, FunctionNull, PullDown>,
south_red: Pin<Gpio8, FunctionNull, PullDown>,
south_yellow: Pin<Gpio9, FunctionNull, PullDown>,
south_green: Pin<Gpio10, FunctionNull, PullDown>,
pedestrian_red: Pin<Gpio11, FunctionNull, PullDown>,
pedestrian_green: Pin<Gpio12, FunctionNull, PullDown>,
pedestrian_button: Pin<Gpio13, FunctionNull, PullDown>,
) -> Self {
Self {
phase_index: 0,
phase_start: 0,
main_traffic_light: TrafficLight::new(
gpio0.into_push_pull_output(),
gpio1.into_push_pull_output(),
gpio2.into_push_pull_output(),
main_red.into_push_pull_output(),
main_yellow.into_push_pull_output(),
main_green.into_push_pull_output(),
),
north_traffic_light: TrafficLight::new(
gpio3.into_push_pull_output(),
gpio4.into_push_pull_output(),
gpio5.into_push_pull_output(),
north_red.into_push_pull_output(),
north_yellow.into_push_pull_output(),
north_green.into_push_pull_output(),
),
south_traffic_light: TrafficLight::new(
gpio6.into_push_pull_output(),
gpio7.into_push_pull_output(),
gpio8.into_push_pull_output(),
south_red.into_push_pull_output(),
south_yellow.into_push_pull_output(),
south_green.into_push_pull_output(),
),
pedestrian_light: PedestrianLight::new(
gpio9.into_push_pull_output(),
gpio10.into_push_pull_output(),
pedestrian_red.into_push_pull_output(),
pedestrian_green.into_push_pull_output(),
),
button: gpio11.into_pull_up_input(),
button: pedestrian_button.into_pull_up_input(),
button_state: false,
}
}
+2 -2
View File
@@ -34,8 +34,6 @@ fn main() -> ! {
display.print("Hello Pico");
let mut traffic_controller = TrafficController::new(
pins.gpio0,
pins.gpio1,
pins.gpio2,
pins.gpio3,
pins.gpio4,
@@ -46,6 +44,8 @@ fn main() -> ! {
pins.gpio9,
pins.gpio10,
pins.gpio11,
pins.gpio12,
pins.gpio13,
);
traffic_controller.phase_start = timer.get_counter().ticks();
traffic_controller.apply_phase(&PHASES[0]);
+16 -14
View File
@@ -1,5 +1,7 @@
use crate::lights::{PedestrianLightColor, TrafficLightColor};
const PHASE_DURATION: u64 = 1_000_000;
pub struct Phase {
pub duration: u64,
pub main: TrafficLightColor,
@@ -12,7 +14,7 @@ pub struct Phase {
pub const PHASES: [Phase; 14] = [
Phase {
duration: 500_000,
duration: PHASE_DURATION,
main: TrafficLightColor::RedYellow,
north: TrafficLightColor::Red,
south: TrafficLightColor::Red,
@@ -21,7 +23,7 @@ pub const PHASES: [Phase; 14] = [
accepts_button_request: true,
},
Phase {
duration: 500_000,
duration: PHASE_DURATION,
main: TrafficLightColor::Green,
north: TrafficLightColor::Red,
south: TrafficLightColor::Red,
@@ -30,7 +32,7 @@ pub const PHASES: [Phase; 14] = [
accepts_button_request: true,
},
Phase {
duration: 500_000,
duration: PHASE_DURATION,
main: TrafficLightColor::Yellow,
north: TrafficLightColor::Red,
south: TrafficLightColor::Red,
@@ -39,7 +41,7 @@ pub const PHASES: [Phase; 14] = [
accepts_button_request: true,
},
Phase {
duration: 500_000,
duration: PHASE_DURATION,
main: TrafficLightColor::Red,
north: TrafficLightColor::Red,
south: TrafficLightColor::Red,
@@ -48,7 +50,7 @@ pub const PHASES: [Phase; 14] = [
accepts_button_request: true,
},
Phase {
duration: 500_000,
duration: PHASE_DURATION,
main: TrafficLightColor::Red,
north: TrafficLightColor::RedYellow,
south: TrafficLightColor::Red,
@@ -57,7 +59,7 @@ pub const PHASES: [Phase; 14] = [
accepts_button_request: true,
},
Phase {
duration: 500_000,
duration: PHASE_DURATION,
main: TrafficLightColor::Red,
north: TrafficLightColor::Green,
south: TrafficLightColor::Red,
@@ -66,7 +68,7 @@ pub const PHASES: [Phase; 14] = [
accepts_button_request: true,
},
Phase {
duration: 500_000,
duration: PHASE_DURATION,
main: TrafficLightColor::Red,
north: TrafficLightColor::Yellow,
south: TrafficLightColor::Red,
@@ -75,7 +77,7 @@ pub const PHASES: [Phase; 14] = [
accepts_button_request: true,
},
Phase {
duration: 500_000,
duration: PHASE_DURATION,
main: TrafficLightColor::Red,
north: TrafficLightColor::Red,
south: TrafficLightColor::Red,
@@ -84,7 +86,7 @@ pub const PHASES: [Phase; 14] = [
accepts_button_request: true,
},
Phase {
duration: 500_000,
duration: PHASE_DURATION,
main: TrafficLightColor::Red,
north: TrafficLightColor::Red,
south: TrafficLightColor::RedYellow,
@@ -93,7 +95,7 @@ pub const PHASES: [Phase; 14] = [
accepts_button_request: true,
},
Phase {
duration: 500_000,
duration: PHASE_DURATION,
main: TrafficLightColor::Red,
north: TrafficLightColor::Red,
south: TrafficLightColor::Green,
@@ -102,7 +104,7 @@ pub const PHASES: [Phase; 14] = [
accepts_button_request: true,
},
Phase {
duration: 500_000,
duration: PHASE_DURATION,
main: TrafficLightColor::Red,
north: TrafficLightColor::Red,
south: TrafficLightColor::Yellow,
@@ -111,7 +113,7 @@ pub const PHASES: [Phase; 14] = [
accepts_button_request: true,
},
Phase {
duration: 500_000,
duration: PHASE_DURATION,
main: TrafficLightColor::Red,
north: TrafficLightColor::Red,
south: TrafficLightColor::Red,
@@ -120,7 +122,7 @@ pub const PHASES: [Phase; 14] = [
accepts_button_request: true,
},
Phase {
duration: 500_000,
duration: PHASE_DURATION,
main: TrafficLightColor::Red,
north: TrafficLightColor::Red,
south: TrafficLightColor::Red,
@@ -129,7 +131,7 @@ pub const PHASES: [Phase; 14] = [
accepts_button_request: false,
},
Phase {
duration: 500_000,
duration: PHASE_DURATION,
main: TrafficLightColor::Red,
north: TrafficLightColor::Red,
south: TrafficLightColor::Red,