// ************************************************************************
// *                                                                      *
// * NAME           : Marisa Johnston                                     *
// * Program Name   : Light Chaser DDRB.ino                               *
// * Date           : 2023-02-27                                          *
// * Desc           : Create a light chaser to turn on LEDs with DDRB     *
// *                                                                      *
// ************************************************************************


int buttonPin     = 6;        // the pin for the button   
int patternNumber = 1;        // tell which pattern will run 
int delayTime     = 100;      // delay in ms between pattern steps 

          
void setup() {
DDRB = B111111;                     // set portB to output 
pinMode(buttonPin, INPUT_PULLUP);   // config button to be an INPUT 
pinMode(7, OUTPUT);                 // config speaker on pin 7
} // end setup()


void loop() {
  if ( digitalRead(buttonPin) == LOW ){    // check if pushed 
    patternNumber = patternNumber +1;      // go to next pattern 
    if (patternNumber == 7){               // check if we exceeded the max patterns 
      patternNumber = 1;                   // if so reset pattern to 1
    }// end if ()
    tone (7,500,100);
    delay(110);
  }// end if()

  if (patternNumber == 1 ) {
    PORTB = B000100;                      // according to binary send power to portB
    // DECIMAL = 16
    delay(delayTime);                     // wait 100 ms

    PORTB = B001100;                       // according to binary send power to portB                              
    delay(delayTime);                     // wait 100 ms 

    PORTB = B011100;                       // according to binary send power to portB
    delay(delayTime);                     // wait 100 ms 
  }

  else if (patternNumber == 2 ) {
    PORTB = B011000;                       // according to binary send power to portB
    delay(delayTime);                     // wait 100 ms 

    PORTB = B010100;                       // according to binary send power to portB
    delay(delayTime);                     // wait 100 ms 

    PORTB = B001100;                       // according to binary send power to portB
    delay(delayTime);                     // wait 100 ms  
  }

  else if (patternNumber == 3 ) {  
    PORTB = B010000;                       // according to binary send power to portB
    delay(delayTime);                     // wait 100 ms 

    PORTB = B001000;                       // according to binary send power to portB
    delay(delayTime);                     // wait 100 ms 

    PORTB = B000100;                       // according to binary send power to portB
    delay(delayTime);                     // wait 100 ms
  }  

  else if (patternNumber == 4 ) {
    PORTB = B010000;                       // according to binary send power to portB
    delay(delayTime);                     // wait 100 ms 

    PORTB = B011000;                       // according to binary send power to portB
    delay(delayTime);                     // wait 100 ms 

    PORTB = B011100;                       // according to binary send power to portB
    delay(delayTime);                     // wait 100 ms  
  }

  else if (patternNumber == 5 ) {
    PORTB = B001100;                       // according to binary send power to portB
    delay(delayTime);                     // wait 100 ms 

    PORTB = B010100;                       // according to binary send power to portB
    delay(delayTime);                     // wait 100 ms 

    PORTB = B011000;                        // according to binary send power to portB
    delay(delayTime);                     // wait 100 ms  
  }

  else if (patternNumber == 6 ) {
    PORTB = B000100;                       // according to binary send power to portB
    delay(delayTime);                     // wait 100 ms 

    PORTB = B001000;                       // according to binary send power to portB
    delay(delayTime);                     // wait 100 ms 

    PORTB = B010000;                       // according to binary send power to portB
    delay(delayTime);                     // wait 100 ms  

  }// end if()

} // end loop()