gear shifter driven by servo
hi everyone, newcomer have few questions in little project have been working on.
i have created simple code controls servo 2 different buttons. when pressed 1 turn servo left , 1 right. problem code works little wrong. servo turns when button pressed down , want make movement once button pressed. if press button real quick, servo goes position , comes back.
i hope don't sound confusing
here video of setup, , code
https://www.youtube.com/watch?v=g4btwh3sod0&feature=youtu.be
i have created simple code controls servo 2 different buttons. when pressed 1 turn servo left , 1 right. problem code works little wrong. servo turns when button pressed down , want make movement once button pressed. if press button real quick, servo goes position , comes back.
i hope don't sound confusing
here video of setup, , code
https://www.youtube.com/watch?v=g4btwh3sod0&feature=youtu.be
code: [select]
#include <servo.h>
servo myservo;
int button7=0;
int button6=0;
int pos=90;
void setup()
{
pinmode(7, input);
pinmode(6, input);
myservo.attach(9);
}
void loop()
{
button7=digitalread(7);
button6=digitalread(6);
myservo.write(pos);
delay(5);
pos=constrain(pos,0,180);
if(button7==1 && button6==0)
{
pos = 0;
}
if(button7==0 && button6==0)
{
pos = 90;
}
if(button7==0 && button6==1)
{
pos = 180;
}
}
1) please edit posting use code tags, explained in sticky thread.
2) buttons wired ground or vcc?
3) code handles 3 button states, perhaps 1 of them neither-button-pressed?
do want servo go somewhere everytime buttons aren't pressed?
2) buttons wired ground or vcc?
3) code handles 3 button states, perhaps 1 of them neither-button-pressed?
do want servo go somewhere everytime buttons aren't pressed?
Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > gear shifter driven by servo
arduino
Comments
Post a Comment