Close

Servo Single Push Button Code

A project log for Smart Shoes

Features of smart shoes: generates electricity, auto lacing, step counting, etc.

Shahid JariwalaShahid Jariwala 07/16/2018 at 09:400 Comments

Image result for arduino servo button

#include <Servo.h>;

 
 // pushbutton pin
 const int buttonPin = 2;

 // servo pin
 const int servoPin = 9;
 Servo servo;

//create a variable to store a counter and set it to 0
int counter = 0;
void setup()
{
  servo.attach (servoPin);
  
  // Set up the pushbutton pins to be an input:
  pinMode(buttonPin, INPUT);
}

void loop()
{
 
  int buttonState;  

  buttonState = digitalRead(buttonPin);

  if (buttonState == LOW) // light the LED
  {
    counter++;
    delay(150);
  }

  if(counter == 0)

{
   servo.write (0);  

}
  else if(counter == 1 )

{

  servo.write (180);  

}

else

{

  counter = 0;

}

}
}

Discussions