Demo entry 6354248

servo motor

   

Submitted by anonymous on Apr 06, 2017 at 03:21
Language: C. Code size: 564 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).