#include <Servo.h>
// Declaring all constants used to correlate pin numbers to input and output devices
const int ORANGE_LED = 5;   
const int BLUE_LED = 6;    
const int RED_LED = 9;     
const int GREEN_LED = 10;
const int BUTTON_A = 2;
const int BUTTON_B = 12;
const int BUTTON_C = 8;
const int BUTTON_D = 7;
const int SERVO_PIN = 11;

// Declaring wiggly as my servo
Servo wiggly;

// declaring bool for whether all lights should be on or off
bool click_ref = 0;

// declaring counter variable for rotating servo periodically
int servo_pos = 0;

void setup() {
  // put your setup code here, to run once:

  // configuring all buttons as input devices
  pinMode(BUTTON_A,INPUT);  
  pinMode(BUTTON_B,INPUT); 
  pinMode(BUTTON_C,INPUT);
  pinMode(BUTTON_D,INPUT); 

  // configuring all LEDs as output devices
  pinMode(ORANGE_LED,OUTPUT);      
  pinMode(BLUE_LED,OUTPUT);      
  pinMode(RED_LED,OUTPUT);     
  pinMode(GREEN_LED,OUTPUT); 

  // designating pin 11 as my servo PWM pin
  wiggly.attach(SERVO_PIN);

  // Configuring speed of transmittion for the serial monitor, so messages can be printed properly
  Serial.begin(9600);            
}

void loop() {
  digitalWrite(BLUE_LED,HIGH);
  digitalWrite(GREEN_LED, HIGH);
  digitalWrite(ORANGE_LED, HIGH);
  digitalWrite(RED_LED, HIGH);
  // 
  while(digitalRead(BUTTON_A) == HIGH){
    // using for loop to incrementely step between rotation positions
    for(int servo_pos = 15; servo_pos <= 120; servo_pos++){
      // Moving servo to starting position degrees first
      wiggly.write(servo_pos);
      // Delaying before switching to 135 degrees
      delay(20);
    }
    for(int servo_pos = 120; servo_pos >= 15; servo_pos--){
      // Moving servo to starting position degrees first
      wiggly.write(servo_pos);
      // Delaying before switching to 135 degrees
      delay(20);
    }
  }
  //
  if(digitalRead(BUTTON_B) == HIGH){
    digitalWrite(BLUE_LED, LOW);
    wiggly.write(90);
    delay(3000);
    digitalWrite(BLUE_LED, LOW);
    wiggly.write(0);
  }
  //
  while(digitalRead(BUTTON_C) == HIGH){
    digitalWrite(ORANGE_LED, LOW);
    delay(100);
    digitalWrite(ORANGE_LED, HIGH);
    delay(100);
    digitalWrite(ORANGE_LED, LOW);
    delay(100);
    digitalWrite(ORANGE_LED, HIGH);

    digitalWrite(BLUE_LED, LOW);
    delay(100);
    digitalWrite(BLUE_LED, HIGH);
    delay(100);
    digitalWrite(BLUE_LED, LOW);
    delay(100);
    digitalWrite(BLUE_LED, HIGH);

    digitalWrite(RED_LED, LOW);
    delay(100);
    digitalWrite(RED_LED, HIGH);
    delay(100);
    digitalWrite(RED_LED, LOW);
    delay(100);
    digitalWrite(RED_LED, HIGH);

    digitalWrite(GREEN_LED, LOW);
    delay(100);
    digitalWrite(GREEN_LED, HIGH);
    delay(100);
    digitalWrite(GREEN_LED, LOW);
    delay(100);
    digitalWrite(GREEN_LED, HIGH);
    delay(100);
  }
  while(digitalRead(BUTTON_D) == HIGH){
    wiggly.write(30);
    digitalWrite(BLUE_LED, LOW);
    delay(100);
    digitalWrite(BLUE_LED, HIGH);
    delay(100);
    digitalWrite(BLUE_LED, LOW);
    delay(100);
    digitalWrite(BLUE_LED, HIGH);

    digitalWrite(GREEN_LED, LOW);
    delay(100);
    digitalWrite(GREEN_LED, HIGH);
    delay(100);
    digitalWrite(GREEN_LED, LOW);
    delay(100);
    digitalWrite(GREEN_LED, HIGH);
    delay(100);
  }

}