diff --git a/src/moduleTests/lightTest.rs b/src/moduleTests/lightTest.rs new file mode 100644 index 0000000..56bf4f3 --- /dev/null +++ b/src/moduleTests/lightTest.rs @@ -0,0 +1,85 @@ +use std::thread; +use std::time::Duration; + +use rppal::gpio::Gpio; + +let gpio = Gpio::new()?; + +let mut indicatorLeftBack = gpio.get(21)?.into_output(); +let mut indicatorRightBack = gpio.get(22)?.into_output(); +let mut brakeLeftBack = gpio.get(23)?.into_output(); +let mut brakeRightBack = gpio.get(24)?.into_output(); +let mut frontLeftHead = gpio.get(25)?.into_output(); +let mut frontRightHead = gpio.get(26)?.into_output(); + +// Blink both indicators + +let mut i = 0; + +while i < 10 { + indicatorLeftBack.set_high(); + indicatorRightBack.set_high(); + thread::sleep(Duration::from_secs(0.7)); + indicatorLeftBack.set_low(); + indicatorRightBack.set_low(); + i = i + 1; +} + +i = 0; + +// Blink left indicator thrice + +while i < 4 { + indicatorLeftBack.set_high(); + thread::sleep(Duration::from_secs(0.7)); + indicatorLeftBack.set_low(); + i = i + 1 +} + +i = 0; + +// Blink right indicator thrice + +while i < 4 { + indicatorRightBack.set_high(); + thread::sleep(Duration::from_secs(0.7)); + indicatorRightBack.set_low(); + i = i + 1 +} + +i = 0; + +// Hold brake lights and blink twice + +brakeLeftBack.set_high(); +brakeRightBack.set_high(); +thread::sleep(Duration::from_secs(3)); +brakeLeftBack.set_low(); +brakeRightBack.set_low(); + +while i < 3 { + brakeLeftBack.set_high(); + brakeRightBack.set_high(); + thread::sleep(Duration::from_secs(0.7)) + brakeLeftBack.set_low(); + brakeRigthBack.set_low(); +} + +i = 0; + +// Turn on headlights and flash twice + +frontLeftHead.set_high(); +frontRightHead.set_high(); +thread::sleep(Duration::from_secs(3)) +frontLeftHead.set_low(); +frontRightHead.set_low(); + +while i < 3 { + frontLeftHead.set_high(); + frontRightHead.set_high(); + thread::sleep(Duration::from_secs(0.7)) + frontLeftHead.set_low(); + frontRightHead.set_low(); +} +