Programming the switches

Build Part 3A

In this video, I will test the switches after they are hooked up.

Switch Hookup


void setup()
{
	pinMode(53, INPUT);
	pinMode(13, OUTPUT);
}

void loop()
{
	if (digitalRead(53) == HIGH)
	{
	        digitalWrite(13, HIGH);
	        delay(2000);
	        digitalWrite(13, LOW);
	}	
}


Build Part 3B

In this video, we will make horse 5 delay after the switch is hit.

Horse 5 Arduino Code

#include 

Stepper horse5(800, 13, 12, 11, 10);

void setup()
{
	horse5.setSpeed(70);
	pinMode(6, INPUT);
}

void loop()
{
	horse5.step(400);
	delay(200);	
	
	while (digitalRead(6) == HIGH)
	{
	       delay(1);
	}
}


Switchboard code


void setup()
{
	pinMode(53, INPUT);
	pinMode(52, OUTPUT);
}

void loop()
{
	if (digitalRead(53) == HIGH)
	{
	        digitalWrite(52, HIGH);
	        delay(5000);
	        digitalWrite(52, LOW);
	        delay(5000);
	}	
}


Build Part 3C

In this video, we will make all five horses go to the start line and wait for the others to get there before starting again.

Horse 1-5 Arduino Code

#include 

Stepper horse5(800, 13, 12, 11, 10);

void setup()
{
	horse5.setSpeed(70);
	pinMode(6, INPUT);
}

void loop()
{
	horse5.step(400);
	delay(200);	
	
	while (digitalRead(6) == HIGH)
	{
	       delay(1);
	}
}


Switchboard code


boolean h1finish = false;
boolean h2finish = false;
boolean h3finish = false;
boolean h4finish = false;
boolean h5finish = false;

void setup()
{
	pinMode(53, INPUT);
	pinMode(52, OUTPUT);
	pinMode(51, INPUT);
	pinMode(50, OUTPUT);
	pinMode(49, INPUT);
	pinMode(48, OUTPUT);
	pinMode(47, INPUT);
	pinMode(46, OUTPUT);
	pinMode(45, INPUT);
	pinMode(44, OUTPUT);
	
}

void loop()
{
	if (digitalRead(53) == HIGH)
	{
	        digitalWrite(52, HIGH);
                h5finish = true;
	}
	
	if (digitalRead(51) == HIGH)
	{
	        digitalWrite(50, HIGH);
                h1finish = true;
	}
	
	if (digitalRead(49) == HIGH)
	{
	        digitalWrite(48, HIGH);
                h4finish = true;
	}
	
	if (digitalRead(47) == HIGH)
	{
	        digitalWrite(46, HIGH);
                h2finish = true;
	}
	
	if (digitalRead(45) == HIGH)
	{
	        digitalWrite(44, HIGH);
                h3finish = true;
	}	
	
	if (h1finish == true && h2finish == true && h3finish == true && h4finish == true && h5finish == true)
	{
		delay(5000);
		digitalWrite(52, LOW);
		digitalWrite(50, LOW);
		digitalWrite(48, LOW);
		digitalWrite(46, LOW);
		digitalWrite(44, LOW);
		delay(5000);
		
		h1finish = false;
		h2finish = false;
		h3finish = false;
		h4finish = false;
		h5finish = false;
	}
}