- Clear all variables
- Connect to Arduino using MATLAB code
- Attach servo motor to Arduino
- Label specific pins to certain variables
- Left and right LEDs
- Approach and Departure gates
- Set up a flag variable
- Prompt the motor in the train to be ready to go forward
- Set the train’s motor speed
- Run while loop to start train’s cycle
- If the approach gate reads a value greater than 250
- Change motor speed to 170
- Set timer
- Set location to urban
- Turn on approach gate red LED
- Turn off approach gate green LED
- Turn off departure gate red LED
- Turn on departure gate green LED
- Set interval for flash of left crossing light to 0.3
- Set interval for flash of right crossing light to 0.6
- End
- If location is urban
- If time is greater than left flash and less than 3.25
- Turn on right LED
- Turn off left LED
- Increment left flash by 0.5
- Else if time is greater than right flash and less than 3.25
- Turn off right LED
- Turn on left LED
- Increment right flash by 0.5
- End
- If time is greater than left flash and less than 3.25
- End
- If time is greater than 1, and location is urban
- Set crossing gate servo to 170
- End
- If time is greater than 3.25, and location is urban
- Change motor speed to 0
- Set crossing gate servo to 100
- Turn off left and right crossing gate LEDs
- End
- If time is greater than 8.25 and location is urban
- Change motor speed to 170
- End
- If the departure gate reads a value greater than 250
- Change motor speed to 255
- Set location to rural
- Turn off approach gate red LED
- Turn on approach gate green LED
- Turn on departure gate red LED
- Turn off departure gate green LED
- End
- If the approach gate reads a value greater than 250
- End