#include <Servo.h>
Servo myservo;
int potpin = A0;
int val;
void setup() {
myservo.attach(9);
}
void loop() {
val = analogRead(potpin);
val = map(val, 0, 1023, 10, 180);
myservo.write(val);
delay(15);
}
include <Servo.h>
int button = 5; //button pin, connect to ground to move servo
int press = 0;
Servo servo;
boolean toggle = true;
void setup()
{
pinMode(13, OUTPUT); //LED on pin 13
pinMode(button, INPUT); //arduino monitor pin state
servo.attach(7); //pin for servo control signal
digitalWrite(5, HIGH); //enable pullups to make pin high
}
Arduino Forum
Toggle switch to move servo motor
Using Arduino
Programming Questions
โ Upcoming deletion of inactive Arduino accounts. Details ๐here๐
Toggle switch to move servo motor
Using Arduino
Programming Questions
yhankru
Jan 2017post #1
I got the code from @zoomkat in the other forum post and I tried if it works for me, however I havent successfully made it. What do you think is missing or problem?
#include <Servo.h>
int button = 5; //button pin, connect to ground to move servo
int press = 0;
Servo servo;
boolean toggle = true;
void setup()
{
pinMode(13, OUTPUT); //LED on pin 13
pinMode(button, INPUT); //arduino monitor pin state
servo.attach(7); //pin for servo control signal
digitalWrite(5, HIGH); //enable pullups to make pin high
}
void loop()
{
press = digitalRead(button);
if (press == LOW)
{
if(toggle)
{
digitalWrite(13, HIGH); // set the LED on
servo.write(160);
toggle = !toggle;
}
else
{
digitalWrite(13, LOW); // set the LED off
servo.write(20);
toggle = !toggle;
}
}
delay(500); //delay for debounce
}