The Core

ABOUT THE VIDEO

In this video, I will go over timing the races.

Here is a modified version of what you saw on the video. I didnt save it.


#include 
 
int in1Pin = 13;
int in2Pin = 12;
int in3Pin = 11;
int in4Pin = 10;
int racenum = 0;
int racestep = 0;
int x = 0;
int rn = 0;

boolean stage = true;
boolean race = false;

Stepper motor(800, in1Pin, in2Pin, in3Pin, in4Pin);  

void setup()
{
  pinMode(7, INPUT);
  pinMode(6, INPUT);
  Serial.begin(9600);
  motor.setSpeed(70);
}


void loop()
{
  
      
  while (stage == true)
  {

    while (digitalRead(7) == HIGH)
    {
      delay(1);
    }
    motor.step(100);
    delay(50);
    if (digitalRead(6) == HIGH)
    {
      stage = false;
      race = true;
    }
  }
    
  while (race == true)
  {
    racenum = random(1,6);
    
    while (digitalRead(6) == HIGH)
    {
      delay(1);
    }
    
     if (racenum == 1)       // 22.55
     {

        while (race == true)
        {
          motor.step(400);
          delay(100);
          if (digitalRead(7) == HIGH)
            {
               race = false;
               stage = true;
            }
        }
    }
    
    if (racenum == 2)       //  23.52
    {
      racestep = 38;
      while (racestep > 0)
      {
        motor.step(400);
        delay(100);
        racestep--;
      }
      while (race == true)
      {
        motor.step(200);
        delay(150);
        if (digitalRead(7) == HIGH)
        {
          race = false;
          getrace = true;
        }
      }
    }
    
    if (racenum == 3)       // 24.65
    {
      racestep = 20;
      while (racestep > 0)
      {
        motor.step(400);
        delay(200);
        racestep--;
      }
      while (race == true)
      {
        motor.step(400);
        delay(100);
        if (digitalRead(7) == HIGH)
        {
          race = false;
          getrace = true;
        }
      }
    }
    
    if (racenum == 4)       // 26.58
    {
      racestep = 20;
      while (racestep > 0)
      {
        motor.step(200);
        delay(100);
        racestep--;
      }
      racestep = 25;
      while (racestep > 0)
      {
        motor.step(400);
        delay(100);
        racestep--;
      }
      while (race == true)
      {
        motor.step(200);
        delay(200);
        if (digitalRead(7) == HIGH)
        {
          race = false;
          getrace = true;
        }
      }
    }
    
    if (racenum == 5)       // 27.5
    {
      racestep = 30;
      while (racestep > 0)
      {
        motor.step(400);
        delay(100);
        racestep--;
      }
      while (race == true)
      {
        motor.step(200);
        delay(200);
        if (digitalRead(7) == HIGH)
        {
          race = false;
          getrace = true;
        }
      }
    }
  }
}