Servo control: extremely confused noob
hello everyone,
i absolute newbie, please forgive me if
a. has been asked before (see below)
b. it's in wrong sub-forum
i have been trying mini servo working time. want rotate 60 degrees on button push , stay there. when button pushed again, want come zero.
i have tried searching , found similar (though not identical) problems. have tried using suggestions, keep getting stuck @ same point.
what happens when run sketch , press button, servo rotates few degrees (about 5, guess) , comes zero. if long press push button, servo rotates in 5 degree steps , after 4 or 5 presses swings zero. tested servo using sweep sketch in examples , servo rotates without problem.
since mini servo, powering off arduino board. once basic structure right , use multiple servos using separate power supply. have put in 10k resistor in circuit. rest pushbutton , servo.
please take @ code , tell me doing wrong. regular toggle switch work better want do?
thank guidance , pointers.
ashok
i absolute newbie, please forgive me if
a. has been asked before (see below)
b. it's in wrong sub-forum
i have been trying mini servo working time. want rotate 60 degrees on button push , stay there. when button pushed again, want come zero.
i have tried searching , found similar (though not identical) problems. have tried using suggestions, keep getting stuck @ same point.
what happens when run sketch , press button, servo rotates few degrees (about 5, guess) , comes zero. if long press push button, servo rotates in 5 degree steps , after 4 or 5 presses swings zero. tested servo using sweep sketch in examples , servo rotates without problem.
since mini servo, powering off arduino board. once basic structure right , use multiple servos using separate power supply. have put in 10k resistor in circuit. rest pushbutton , servo.
please take @ code , tell me doing wrong. regular toggle switch work better want do?
thank guidance , pointers.
ashok
code: [select]
#include <servo.h>
int servopin = 9; //servo on pin 9
int buttpin = 3; //push button on pin 3
servo servo01; //plan have many servos
int pos = 0; //servo position
int buttonstate = 1; //reading button state
void setup()
{
servo01.attach(9); //servo atached
pinmode(buttpin, input); //button initialised
pinmode(servopin, output);
}
void loop()
{
buttonstate = digitalread(buttpin);
if (buttonstate == high)
{
for(pos = 0; pos < 60; pos = pos+1)
{
servo01.write(pos);
delay(10);
}
}
else if (buttonstate == low)
{
for(pos < 60; pos = 0; pos = pos-1)
servo01.write(pos);
delay(10);
}
}
please show how button wired.
Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > Servo control: extremely confused noob
arduino
Comments
Post a Comment