1A - Finish Switch Board

ABOUT THE COURSE

There were a couple of changes to the code after the video. Be sure to check the code posted below.

Video #1

  boolean h1finish = false;
  boolean h2finish = false;
  boolean h3finish = false;
  boolean h4finish = false;
  boolean h5finish = false;
  
  int first = 0;
  int second = 0;
  int third = 0;
  int fourth = 0;
  int fifth = 0;
  
  int lastrace = 0;
  
  int nextracenum = 0;
  long nextraceodds = 0;
  long lastraceodds = 0;
  long nro = 0;
  
  int h12odds = 0;
  int h13odds = 0;
  int h14odds = 0;
  int h15odds = 0;
  int h23odds = 0;
  int h24odds = 0;
  int h25odds = 0;
  int h34odds = 0;
  int h35odds = 0;
  int h45odds = 0;
  
  int oddssum = 0;
  int oddssum1 = 0;
  int oddssum2 = 0;
  int oddssum3 = 0;
  int oddssum4 = 0;
  int oddssum5 = 0;
  int oddssum6 = 0;
  int oddssum7 = 0;
  int oddssum8 = 0;
  int oddssum9 = 0;
  int oddssum10 = 0;
  
  int oddstotal = 0;
  
  int winner = 0;
  int racenum = 0;
  

  void setup()
  {
    pinMode(45, INPUT);
    pinMode(47, INPUT);
    pinMode(49, INPUT);
    pinMode(51, INPUT);
    pinMode(53, INPUT);
    
    pinMode(52, OUTPUT);
    pinMode(50, OUTPUT);
    pinMode(48, OUTPUT);
    pinMode(46, OUTPUT);
    pinMode(44, OUTPUT);
    
    digitalWrite(52, LOW);
    digitalWrite(50, LOW);
    digitalWrite(48, LOW);
    digitalWrite(46, LOW);
    digitalWrite(44, LOW);
    
    Serial.begin(9600);
    randomSeed(analogRead(0));
  }
  
  void loop()
  {
    if (digitalRead(53) == HIGH && h5finish == false)
    {
      h5finish = true;
      digitalWrite(52, HIGH);

      if (first == 0)
      {
        first = 5;
      }
      else if (second == 0)
      {
        second = 5;
      }
      else if (third == 0)
      {
        third = 5;
      }
      else if (fourth == 0)
      {
        fourth = 5;
      }
      else if (fifth == 0)
      {
        fifth = 5;
      }
    }
    
    if (digitalRead(51) == HIGH && h4finish == false)
    {
        digitalWrite(50, HIGH);
        h4finish = true;

        if (first == 0)
        {
          first = 4;
        }
        else if (second == 0)
        {
          second = 4;
        }
        else if (third == 0)
        {
          third = 4;
        }
        else if (fourth == 0)
        {
          fourth = 4;
        }
        else if (fifth == 0)
        {
          fifth = 4;
        }
      }
    
      if (digitalRead(49) == HIGH && h3finish == false)
      {
        digitalWrite(48, HIGH);
        h3finish = true;

        if (first == 0)
        {
          first = 3;
        }
        else if (second == 0)
        {
          second = 3;
        }
        else if (third == 0)
        {
          third = 3;
        }
        else if (fourth == 0)
        {
          fourth = 3;
        }
        else if (fifth == 0)
        {
          fifth = 3;
        }
      }
    
      if (digitalRead(47) == HIGH && h2finish == false)
      {
        digitalWrite(46, HIGH);
        h2finish = true;

        if (first == 0)
        {
          first = 2;
        }
        else if (second == 0)
        {
          second = 2;
        }
        else if (third == 0)
        {
          third = 2;
        }
        else if (fourth == 0)
        {
          fourth = 2;
        }
        else if (fifth == 0)
        {
          fifth = 2;
        }
      }
    
      if (digitalRead(45) == HIGH && h1finish == false)
      {
        digitalWrite(44, HIGH);
        h1finish = true;
 
        if (first == 0)
        {
          first = 1;
        }
        else if (second == 0)
        {
          second = 1;
        }
        else if (third == 0)
        {
          third = 1;
        }
        else if (fourth == 0)
        {
          fourth = 1;
        }
        else if (fifth == 0)
        {
          fifth = 1;
        }
      }
        
    if (h1finish == true && h2finish == true && h3finish == true && h4finish == true && h5finish == true)
    {

      
      if (first == 1 && second == 2)
      {
        lastrace = 0;
      }
      else if (first == 2 && second == 1)
      {
        lastrace = 0;
      }
      else if (first == 1 && second == 3)
      {
        lastrace = 1;
      }
      else if (first == 3 && second == 1)
      {
        lastrace = 1;
      }
      else if (first == 1 && second == 4)
      {
        lastrace = 2;
      }
      else if (first == 4 && second == 1)
      {
        lastrace = 2;
      }
      else if (first == 1 && second == 5)
      {
        lastrace = 3;
      }
      else if (first == 5 && second == 1)
      {
        lastrace = 3;
      }
      else if (first == 2 && second == 3)
      {
        lastrace = 4;
      }
      else if (first == 3 && second == 2)
      {
        lastrace = 4;
      }
      else if (first == 2 && second == 4)
      {
        lastrace = 5;
      }
      else if (first == 4 && second == 2)
      {
        lastrace = 5;
      }
      else if (first == 2 && second == 5)
      {
        lastrace = 6;
      }
      else if (first == 5 && second == 2)
      {
        lastrace = 6;
      }
      else if (first == 3 && second == 4)
      {
        lastrace = 7;
      }
      else if (first == 4 && second == 3)
      {
        lastrace = 7;
      }
      else if (first == 3 && second == 5)
      {
        lastrace = 8;
      }
      else if (first == 5 && second == 3)
      {
        lastrace = 8;
      }
      else if (first == 4 && second == 5)
      {
        lastrace = 9;
      }
      else if (first == 5 && second == 4)
      {
        lastrace = 9;
      }   
            

      nextraceodds = random(10,35);
      
      while (nextraceodds == lastraceodds)
      {
        nextraceodds = random(10,35);
      }
      
      lastraceodds = nextraceodds;
      

      nro = nextraceodds * 1000;   // 25 * 1000 = 25000
      nro = nro + lastrace; // 25003

      
      switch(nextraceodds)
    {
      case 10:
        h12odds = 14;
        h13odds = 9;
        h14odds = 39;
        h15odds = 5;
        h23odds = 11;
        h24odds = 47;
        h25odds = 6;
        h34odds = 23;
        h35odds = 3;
        h45odds = 12;
      break;

      case 11:
        h12odds = 9;
        h13odds = 21;
        h14odds = 11;
        h15odds = 36;
        h23odds = 6;
        h24odds = 3;
        h25odds = 10;
        h34odds = 7;
        h35odds = 23;
        h45odds = 12;
      break;
      
      case 12:
        h12odds = 19;
        h13odds = 3;
        h14odds = 6;
        h15odds = 25;
        h23odds = 9;
        h24odds = 18;
        h25odds = 76;
        h34odds = 4;
        h35odds = 17;
        h45odds = 34;
      break;
      
      case 13:
        h12odds = 10;
        h13odds = 7;
        h14odds = 6;
        h15odds = 4;
        h23odds = 23;
        h24odds = 20;
        h25odds = 13;
        h34odds = 14;
        h35odds = 9;
        h45odds = 8;
      break;
      
      case 14:
        h12odds = 2;
        h13odds = 34;
        h14odds = 8;
        h15odds = 5;
        h23odds = 49;
        h24odds = 12;
        h25odds = 7;
        h34odds = 200;
        h35odds = 119;
        h45odds = 29;
      break;
      
      case 15:
        h12odds = 95;
        h13odds = 4;
        h14odds = 9;
        h15odds = 37;
        h23odds = 21;
        h24odds = 49;
        h25odds = 200;
        h34odds = 2;
        h35odds = 8;
        h45odds = 19;
      break;
      
      case 16:
        h12odds = 59;
        h13odds = 5;
        h14odds = 23;
        h15odds = 18;
        h23odds = 9;
        h24odds = 42;
        h25odds = 33;
        h34odds = 4;
        h35odds = 3;
        h45odds = 14;
      break;
      
      case 17:
        h12odds = 32;
        h13odds = 44;
        h14odds = 109;
        h15odds = 25;
        h23odds = 5;
        h24odds = 12;
        h25odds = 3;
        h34odds = 17;
        h35odds = 4;
        h45odds = 10;
      break;
      
      case 18:
        h12odds = 4;
        h13odds = 8;
        h14odds = 13;
        h15odds = 5;
        h23odds = 10;
        h24odds = 16;
        h25odds = 6;
        h34odds = 33;
        h35odds = 12;
        h45odds = 20;
      break;
      
      case 19:
        h12odds = 2;
        h13odds = 7;
        h14odds = 5;
        h15odds = 8;
        h23odds = 15;
        h24odds = 11;
        h25odds = 17;
        h34odds = 38;
        h35odds = 61;
        h45odds = 43;
      break;

      case 20:
        h12odds = 38;
        h13odds = 2;
        h14odds = 7;
        h15odds = 24;
        h23odds = 16;
        h24odds = 60;
        h25odds = 200;
        h34odds = 3;
        h35odds = 10;
        h45odds = 37;
      break;
      
      case 21:
        h12odds = 8;
        h13odds = 161;
        h14odds = 12;
        h15odds = 24;
        h23odds = 26;
        h24odds = 2;
        h25odds = 4;
        h34odds = 40;
        h35odds = 80;
        h45odds = 6;
      break;
      
      case 22:
        h12odds = 6;
        h13odds = 12;
        h14odds = 3;
        h15odds = 36;
        h23odds = 16;
        h24odds = 4;
        h25odds = 49;
        h34odds = 8;
        h35odds = 11;
        h45odds = 24;
      break;
      
      case 23:
        h12odds = 8;
        h13odds = 29;
        h14odds = 200;
        h15odds = 9;
        h23odds = 6;
        h24odds = 42;
        h25odds = 2;
        h34odds = 159;
        h35odds = 7;
        h45odds = 47;
      break;
      
      case 24:
        h12odds = 2;
        h13odds = 47;
        h14odds = 108;
        h15odds = 18;
        h23odds = 17;
        h24odds = 6;
        h25odds = 3;
        h34odds = 20;
        h35odds = 16;
        h45odds = 19;
      break;

      case 25:
        h12odds = 8;
        h13odds = 43;
        h14odds = 108;
        h15odds = 18;
        h23odds = 17;
        h24odds = 6;
        h25odds = 3;
        h34odds = 20;
        h35odds = 16;
        h45odds = 19;
      break;
      
      case 26:
        h12odds = 2;
        h13odds = 8;
        h14odds = 4;
        h15odds = 15;
        h23odds = 14;
        h24odds = 7;
        h25odds = 26;
        h34odds = 29;
        h35odds = 107;
        h45odds = 88;
      break;
      
      case 27:
        h12odds = 5;
        h13odds = 7;
        h14odds = 28;
        h15odds = 14;
        h23odds = 3;
        h24odds = 12;
        h25odds = 6;
        h34odds = 16;
        h35odds = 8;
        h45odds = 33;
      break;

      case 28:
        h12odds = 3;
        h13odds = 19;
        h14odds = 2;
        h15odds = 21;
        h23odds = 38;
        h24odds = 4;
        h25odds = 48;
        h34odds = 9;
        h35odds = 99;
        h45odds = 24;
      break;

      case 29:
        h12odds = 27;
        h13odds = 9;
        h14odds = 136;
        h15odds = 13;
        h23odds = 4;
        h24odds = 61;
        h25odds = 6;
        h34odds = 20;
        h35odds = 2;
        h45odds = 3;
      break;

      case 30:
        h12odds = 2;
        h13odds = 7;
        h14odds = 63;
        h15odds = 12;
        h23odds = 3;
        h24odds = 26;
        h25odds = 5;
        h34odds = 21;
        h35odds = 4;
        h45odds = 36;
      break;

      case 31:
        h12odds = 11;
        h13odds = 14;
        h14odds = 6;
        h15odds = 43;
        h23odds = 7;
        h24odds = 3;
        h25odds = 21;
        h34odds = 4;
        h35odds = 28;
        h45odds = 12;
      break;

      case 32:
        h12odds = 8;
        h13odds = 86;
        h14odds = 18;
        h15odds = 17;
        h23odds = 19;
        h24odds = 3;
        h25odds = 4;
        h34odds = 30;
        h35odds = 40;
        h45odds = 6;
      break;

      case 33:
        h12odds = 14;
        h13odds = 29;
        h14odds = 6;
        h15odds = 109;
        h23odds = 9;
        h24odds = 2;
        h25odds = 34;
        h34odds = 4;
        h35odds = 70;
        h45odds = 15;
      break;

      case 34:
        h12odds = 5;
        h13odds = 9;
        h14odds = 17;
        h15odds = 16;
        h23odds = 4;
        h24odds = 8;
        h25odds = 7;
        h34odds = 14;
        h35odds = 13;
        h45odds = 25;
      break;
    }
    
    oddssum = h12odds + h13odds + h14odds + h15odds + h23odds + h24odds + h25odds + h34odds + h35odds + h45odds;

    oddssum1 = int(oddssum / h12odds); 
    oddssum2 = int(oddssum / h13odds + oddssum1);
    oddssum3 = int(oddssum / h14odds + oddssum2);  
    oddssum4 = int(oddssum / h15odds + oddssum3);
    oddssum5 = int(oddssum / h23odds + oddssum4);
    oddssum6 = int(oddssum / h24odds + oddssum5);
    oddssum7 = int(oddssum / h25odds + oddssum6);
    oddssum8 = int(oddssum / h34odds + oddssum7);
    oddssum9 = int(oddssum / h35odds + oddssum8);
    oddssum10 = int(oddssum / h45odds + oddssum9);
    
    winner = random(1,oddssum10+1);

if (winner > 0 && winner <= oddssum1 )   
    {
      racenum = random(1,7);
      switch(racenum)
      {
        case 1:
        nextracenum = 20;
        case 2:
        nextracenum = 21;
        case 3:
        nextracenum = 40;
        case 4:
        nextracenum = 41;
        case 5:
        nextracenum = 60;
        case 6:
        nextracenum = 61;
        break;
      }
    }
    else if (winner > oddssum1 && winner <= oddssum2) 
    {
      racenum = random(1,7);
      switch(racenum)
      {
        case 1:
        nextracenum = 22;
        break;      
        case 2:
        nextracenum = 23;
        break;      
        case 3:
        nextracenum = 42;
        break;     
        case 4:
        nextracenum = 43;
        break;     
        case 5:
        nextracenum = 62;
        break; 
        case 6:
        nextracenum = 63;
        break;
      }
    }
    else if (winner > oddssum2 && winner <= oddssum3)
    {
      racenum = random(1,7);
      switch(racenum)
      {
        case 1:
        nextracenum = 24;
        break;
        case 2:
        nextracenum = 25;
        break;
        case 3:
        nextracenum = 44;
        break;
        case 4:
        nextracenum = 45;
        break;
        case 5:
        nextracenum = 64;
        break;
        case 6:
        nextracenum = 65;
        break;
      }
    }
    else if (winner > oddssum3 && winner <= oddssum4)
    {
      racenum = random(1,7);
      switch(racenum)
      {
        case 1:
        nextracenum = 26;
        break;
        case 2:
        nextracenum = 27;
        break;
        case 3:
        nextracenum = 46;
        break;
        case 4:
        nextracenum = 47;
        break;
        case 5:
        nextracenum = 66;
        break;
        case 6:
        nextracenum = 67;
        break;
      }
    }
    else if (winner > oddssum4 && winner <= oddssum5)
    {
      racenum = random(1,7);
      switch(racenum)
      {
        case 1:
        nextracenum = 28;
        break;
        case 2:
        nextracenum = 29;
        break;
        case 3:
        nextracenum = 48;
        break;
        case 4:
        nextracenum = 49;
        break;
        case 5:
        nextracenum = 68;
        break;
        case 6:
        nextracenum = 69;
        break;
      }
    }
    else if (winner > oddssum5 && winner <= oddssum6)
    {
      racenum = random(1,7);
      switch(racenum)
      {
        case 1:
        nextracenum = 30;
        break;
        case 2:
        nextracenum = 31;
        break;
        case 3:
        nextracenum = 50;
        break;
        case 4:
        nextracenum = 51;
        break;
        case 5:
        nextracenum = 70;
        break;
        case 6:
        nextracenum = 71;
        break;
      }
    }
    else if (winner > oddssum6 && winner <= oddssum7)
    {
      racenum = random(1,7);
      switch(racenum)
      {
        case 1:
        nextracenum = 32;
        break;
        case 2:
        nextracenum = 33;
        break;
        case 3:
        nextracenum = 52;
        break;
        case 4:
        nextracenum = 53;
        break;
        case 5:
        nextracenum = 72;
        break;
        case 6:
        nextracenum = 73;
        break;
      }
    }
    else if (winner > oddssum7 && winner <= oddssum8)
    {
      racenum = random(1,7);
      switch(racenum)
      {
        case 1:
        nextracenum = 34;
        break;
        case 2:
        nextracenum = 35;
        break;
        case 3:
        nextracenum = 54;
        break;
        case 4:
        nextracenum = 55;
        break;
        case 5:
        nextracenum = 74;
        break;
        case 6:
        nextracenum = 75;
        break;
      }
    }
    else if (winner > oddssum8 && winner <= oddssum9)
    {
      racenum = random(1,7);
      switch(racenum)
      {
        case 1:
        nextracenum = 36;
        break;
        case 2:
        nextracenum = 37;
        break;
        case 3:
        nextracenum = 56;
        break;
        case 4:
        nextracenum = 57;
        break;
        case 5:
        nextracenum = 76;
        break;
        case 6:
        nextracenum = 77;
        break;
      }
    }
    else if (winner > oddssum9 && winner <= oddssum10)
    {
      racenum = random(1,7);
      switch(racenum)
      {
        case 1:
        nextracenum = 38;
        break;
        case 2:
        nextracenum = 39;
        break;
        case 3:
        nextracenum = 58;
        break;
        case 4:
        nextracenum = 59;
        break;
        case 5:
        nextracenum = 78;
        break;
        case 6:
        nextracenum = 79;
        break;
      }
    }
    

    nro = nro + (nextracenum * 10);  // 65 = 650 + 25005 = 25655
    
    
    Serial.write(nro);
    Serial.print(nro);
    
    delay(3000);
    
    digitalWrite(52, LOW);
    digitalWrite(50, LOW);
    digitalWrite(48, LOW);
    digitalWrite(46, LOW);
    digitalWrite(44, LOW);
      
      delay(7500);
  
      lastrace = 0;
      first = 0;
      second = 0;
      third = 0;
      fourth = 0;
      fifth = 0;
  
      h1finish = false;
      h2finish = false;
      h3finish = false;
      h4finish = false;
      h5finish = false;    
    }
  }


1B - Start Switch Board

ABOUT THE COURSE

Most of the material we have already gone over. We did add digital pin #2 into the mix for input from the countdown clock

Video #2

 boolean h1staged = false;
  boolean h2staged = false;
  boolean h3staged = false;
  boolean h4staged = false;
  boolean h5staged = false;
  
  void setup()
  {
    pinMode(45, INPUT); // horse
    pinMode(47, INPUT); // horse 
    pinMode(49, INPUT); // horse 
    pinMode(51, INPUT); 
    pinMode(53, INPUT); 
    pinMode(52, OUTPUT);
    pinMode(50, OUTPUT);
    pinMode(48, OUTPUT);
    pinMode(46, OUTPUT);
    pinMode(44, OUTPUT); 
    
    pinMode(2, INPUT);
    
    digitalWrite(52, LOW);
    digitalWrite(50, LOW);
    digitalWrite(48, LOW);
    digitalWrite(46, LOW);
    digitalWrite(44, LOW);
    
    delay(15000);
    
  }
  
  void loop()
  {
    if (digitalRead(53) == HIGH && h5staged == false)
    {
      digitalWrite(52, HIGH);
      h5staged = true;
    }
    if (digitalRead(49) == HIGH && h4staged == false)
    {
      digitalWrite(48, HIGH);
      h4staged = true;
    }
    if (digitalRead(45) == HIGH && h3staged == false)
    {
      digitalWrite(44, HIGH);
      h3staged = true;
    }
    if (digitalRead(47) == HIGH && h2staged == false)
    {
      digitalWrite(46, HIGH);
      h2staged = true;
    }
    if (digitalRead(51) == HIGH && h1staged == false)
    {
      digitalWrite(50, HIGH);
      h1staged = true;
    }
    
    if (h1staged == true && h2staged == true && h3staged == true && h4staged == true && h5staged == true)
    {
      while (digitalRead(2) == HIGH)
      {
        delay(1);
      }
      
      digitalWrite(52, LOW);
      digitalWrite(50, LOW);
      digitalWrite(48, LOW);
      digitalWrite(46, LOW);
      digitalWrite(44, LOW);
      
      h1staged = false;
      h2staged = false;
      h3staged = false;
      h4staged = false;
      h5staged = false;
    
      delay(6000);
    
    }  
  }