Part 1

Part 2

Part 3

Part 4

Part 5

Part 6

int potValue = 0;
int led1Pin = 7;
int led2Pin = 8;
int led3Pin = 9;
int led4Pin = 10;
int button1Pin = 33;
int button2Pin = 34;
int button3Pin = 36;
int switchPin = 35;

int delayLength = 200;
int randomNumber = 1;

void setup() {
  Serial.begin(9600);

  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  pinMode(led3Pin, OUTPUT);
  pinMode(led4Pin, OUTPUT);
  
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);
  pinMode(button3Pin, INPUT);
  pinMode(switchPin, INPUT);
  
}

void loop() {

  delayLength = analogRead(A13);

  if(digitalRead(button1Pin) == HIGH) {

      digitalWrite(led1Pin, HIGH);
      digitalWrite(led2Pin, HIGH);
      digitalWrite(led3Pin, HIGH);
      digitalWrite(led4Pin, HIGH);

      delay(delayLength);

      digitalWrite(led1Pin, LOW);
      digitalWrite(led2Pin, LOW);
      digitalWrite(led3Pin, LOW);
      digitalWrite(led4Pin, LOW);
      
      delay(delayLength);
    
  } else if(digitalRead(button2Pin) == HIGH) {
    
      if(digitalRead(switchPin) == HIGH) {
        
          digitalWrite(led1Pin, HIGH);
          delay(delayLength);
          digitalWrite(led1Pin, LOW);
          digitalWrite(led2Pin, HIGH);
          delay(delayLength);
          digitalWrite(led2Pin, LOW);
          digitalWrite(led3Pin, HIGH);
          delay(delayLength);
          digitalWrite(led3Pin, LOW);
          digitalWrite(led4Pin, HIGH);
          delay(delayLength);
          digitalWrite(led4Pin, LOW);
          
      } else {

          digitalWrite(led4Pin, HIGH);
          delay(delayLength);
          digitalWrite(led4Pin, LOW);
          digitalWrite(led3Pin, HIGH);
          delay(delayLength);
          digitalWrite(led3Pin, LOW);
          digitalWrite(led2Pin, HIGH);
          delay(delayLength);
          digitalWrite(led2Pin, LOW);
          digitalWrite(led1Pin, HIGH);
          delay(delayLength);
          digitalWrite(led1Pin, LOW);
        
      }

  } else if (digitalRead(button3Pin) == HIGH) {

      randomNumber = random(1, 5);
      if (randomNumber == 4) {

          digitalWrite(led4Pin, HIGH);
          delay(delayLength);
          digitalWrite(led4Pin, LOW);
        
      } else if (randomNumber == 3) {

          digitalWrite(led3Pin, HIGH);
          delay(delayLength);
          digitalWrite(led3Pin, LOW);
        
      } else if (randomNumber == 2) {

          digitalWrite(led2Pin, HIGH);
          delay(delayLength);
          digitalWrite(led2Pin, LOW);
        
      } else if (randomNumber == 1) {

          digitalWrite(led1Pin, HIGH);
          delay(delayLength);
          digitalWrite(led1Pin, LOW);
        
      }
      
  
}


0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.