// this function simulates normal light condition when called at every loop // it automatically transitions from green to red signal by using the OrangeTransitionCounter void UpdateWithLightTransition(bool goSignal, bool turnLight, bool pedLight, int orangeLightTime) { // if green or go signal turn off transitioning process // and only light up the green light if (goSignal) { transitionState = 0; GreenLight(); } // if red signal and green light was previously on // start transitioning to red by firt turning on the // orange light else if(!goSignal && ledGreen.IsOn() && transitionState == 0) { OrangeLight(); transitionState = 1; OrangeTransitionCounter.Reset(); } // if red signal and greenlight was not on, directly // switch on the red light else if(!goSignal && !ledGreen.IsOn() && transitionState == 0) RedLight(); // check if we are still transitioning to red light // if orangeTransitionCounter has passed orangeLightTime interval // turn on the Red light only if (transitionState == 1) { if (OrangeTransitionCounter.GetCounter() < orangeLightTime) OrangeLight(); else transitionState = 2; } if (transitionState == 2) RedLight(); if (turnLight) ledFilterTurn.SwitchOn(); else ledFilterTurn.SwitchOff(); // ped lights turn on only when the normal lights are in red signal if (pedLight && ledRed.IsOn()) ledPed.SwitchOn(); else ledPed.SwitchOff(); }
void SetPins(int pinGreenLED, int pinOrangeLED, int pinRedLED, int pinFilterTurnLED, int pinPedLED, int pinBuzzer) { ledGreen.SetPin(pinGreenLED); ledGreen.SwitchOff(); ledOrange.SetPin(pinOrangeLED); ledOrange.SwitchOff(); ledRed.SetPin(pinRedLED); ledRed.SwitchOff(); ledFilterTurn.SetPin(pinFilterTurnLED); ledFilterTurn.SwitchOff(); ledPed.SetPin(pinPedLED); ledPed.SwitchOff(); crossingBuzzer.SetPin(pinBuzzer); crossingBuzzer.SetFrequency(BUZZER_FREQ); crossingBuzzer.TurnOffAlarm(); }
// this function lights the orange light only switching off // the turn and the ped light as well void RoadWorkLightOnly(){ OrangeLight(); ledPed.SwitchOff(); ledFilterTurn.SwitchOff(); }
// this function lights emergency light only switching off // the turn and the ped lights as well void EmergencyLightOnly() { RedLight(); ledPed.SwitchOff(); ledFilterTurn.SwitchOff(); }
// this function lights the orange light only void OrangeLight() { ledGreen.SwitchOff(); ledOrange.SwitchOn(); ledRed.SwitchOff(); }