Demo entry 6353172

servo motor

   

Submitted by anonymous on Mar 31, 2017 at 01:25
Language: C. Code size: 572 Bytes.

#include <Servo.h>

// create servo name
Servo myservo;

int pos = 0; // variable to store the servo position 
int button = 2; // The button will be on Pin 2 

void setup() 
{ 
 myservo.attach(9); // attaches the servo on pin 9 to the servo object
 pinMode(pos, OUTPUT);
 pinMode(button, INPUT);
 digitalWrite (button, LOW);
} 

void loop() 
{ 
 // goes from 0 degrees to 90 degrees
 if (digitalRead(button) == LOW)
 for(pos = 0; pos < 90; pos += 90) 
 {
 myservo.write(pos);
  delay(50);
  // waits 50ms for the servo to reach the position 
 } 

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).