Technical description – What is the goal of the program?
Variables:
a = variable that contains the arduino object controlled by the arduino class. Used to call the class functions of the arduino class
arrival_Gate_Sensor = used to store the arrival gate sensor signal reading at the beginning until the location of the train is determined
departure_Gate_Sensor = used to store the departure gate sensor signal reading at the beginning until the location of the train is determined
t1 = Timer 1 – used to store the time from the beginning of the program until the train location of the train is determined, controls the timing sequence of the railroad crossing lights in combination with the variable Swi
Swi = Switch – set to toc(t1) then divided by the time in seconds that railroad gate lights are swapped, the decimal portion of this variable is then discarded. The modulus is then found between the remaining integer and 2. The result is a number that alternates between a 1 and a 0 at the desired time interval.
ag = Arrival Gate – used as a boolean to determine if the code for the active and inactive sensor signal has been run at the arrival gate, ensures the active and inactive coding is run only once for each time the sensor changes state
dg = Departure Gate – used as a boolean to determine if the code for the active and inactive sensor signal has been run at the departure gate, ensures the active and inactive coding is run only once for each time the sensor changes state
first_Train_Timer = starts when the first train trips the arrival gate sensor, used to control the crossing lights and gate as the first train is traveling through the urban area, clears at the departure gate
second_Train_Timer = starts when the second train trips the arrival gate sensor, used to control the crossing lights and gate as the second train is traveling through the urban area and the first train timer does not exist, clears at the departure gate
ag1 = arrival gate train 1 – used as boolean logic to determine if the first train has passed through the arrival gate, resets at the departure gate
sensor_Read = used to store the sensor readings for the arrival and departure gate and is then used, readings are not taken at the same time, the arrival gate reading is taken then tested, then the departure gate reading is taken and tested, this cycle then repeats.
Arduino commands used in the creation of the railroad program:
arduino(comPort) – constructor, connects to the board and creates an arduino object
arduino_object.pinMode(pin, str) – sets the digital pins of the arduino to be either inputs or outputs
arduino_object.digitalWrite(pin, value) – pin is the number of the digital pin to which the digital output is to be performed, value is the value to assign the pin (either a 1 or 0)
arduino_object.analogRead(pin) – performs analog input on the arduino pin, returns a value between 0 and 1023
arduino_object.servoAttach(pin) – attaches a servo to a pin
arduino_object.servoWrite(pin, value) – writes an angle to a given servo
arduino_object.motorSpeed(num, val) – Sets the speed of a DC motor
arduino_object.motorRun(num, dir) – runs a given DC motor, num is the number of the motor to run, dir can either be βforwardβ to run the motor in the forward direction, βbackwardβ to run the motor in the reverse direction, or βreleaseβ to stop the motor