#include <ezButton.h>
#include <Servo.h>

/// constants won't change
const int PWM = 2; // the number of the LED pin
const int DIR = 3;
const int BUT = 6; // the number of the pushbutton pin
int BUT2 = 5;
int HALL1 = 8;
int HALL2 = 9;
int HALL3 = 10;
int HALL4 = 11;
int state1 = 0;
int state2 = 0;
int state3 = 0;
int state4 = 0;
Servo Myservo;
int pos=0;

ezButton button(BUT);  // create ezButton object that attach to pin 7;

// variables will change:
int PWMState = LOW;   // the current state of LED

void setup() {
  button.setDebounceTime(50); // set debounce time to 50 milliseconds
  pinMode(HALL1, INPUT);   
pinMode(HALL2, INPUT); 
pinMode(HALL3, INPUT); 
pinMode(HALL4, INPUT);  
Myservo.attach(4);
Myservo.write(0);
}

void loop() {
  state1 = digitalRead(HALL1);
  state2 = digitalRead(HALL2);
  state3 = digitalRead(HALL3);
  state4 = digitalRead(HALL4);
  button.loop(); // MUST call the loop() function first

  if(button.isPressed()) {
    Myservo.write(180);

    // toggle state of LED
    PWMState = !PWMState;

    // control LED arccoding to the toggleed sate
    digitalWrite(PWM, PWMState);
    digitalWrite(DIR, HIGH); 
  }
if (digitalRead(BUT2)==LOW) { 
  Serial.println("DOWN");
  digitalWrite(PWM, HIGH);
  digitalWrite(DIR, LOW);
  Myservo.write(0);
}
if ((state1 == LOW) && (state2 == LOW) && (state3 == LOW) && (state4 == LOW)){  
  Serial.println("SHAPES IN");
  digitalWrite(PWM, LOW);
  digitalWrite(DIR, LOW);
}
}