Go Down

Topic: im a noob really need help for programing  (Read 399 times) previous topic - next topic

Kilian03

so im doing a project where i need to move two servos with the push of a button. when the button is pushed both of the servos should turn 90 degrees but each of them in the opposit direction. im in a real hurry and i am not able to code and this would be the only time i would need coding. the only thing i have is a arduino nano. i would appreciate if some one could do this for me or explain it to me. ive almost watched every youtube video and read  a lot  of the stuff in this forum but im not able to code it . please help

spycatcher2k

Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.


spycatcher2k

Nope - I can't think of anyone who will do YOUR work for free!

You can't even be bothered to try!

My price is now £100
Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

spycatcher2k

If you want someone to write code for you, expect to pay. If you make an attempt, and need help, then that help is offered freely.
Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

wvmarle

Can't you find a starting point (or even a near-ready sketch) in the examples that come with the Servo library?

Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Kilian03

yes i manged to get e servo continius rotating 90 degrees but i dont know how to get a button involved and ow to get a second servo that turns in the opposit direction

Kilian03

#include <Servo.h>

Servo myservo;  

int pos = 0;  
void setup() {
myservo.attach(9);  

void loop() {
for (pos = 0; pos <= 90; pos += 1) {
  // in steps of 1 degree
  myservo.write(pos);            
  delay(2);                      
}
for (pos = 90; pos >= 0; pos -= 1) {
  myservo.write(pos);              
  delay(10);                    
}
}

thats how far i got

wvmarle

Just change the angle for the other one. One goes from 0 to 90, the other from 90 to 0. Or 90-pos.

For buttons, lots of examples around as well.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Kilian03


#include <Servo.h>

Servo myservo; 

int pos = 0;   
void setup() {
  myservo.attach(9); 

void loop() {
  for (pos = 0; pos <= 90; pos += 1) {
   
    myservo.write(pos);             
    delay(2);                     
  }
  for (pos = 90; pos >= 0; pos -= 1) {
    myservo.write(pos);             
    delay(10);                     
  }
}


#include <Servo.h>

Servo myservo2; 

int pos = 0;   
void setup() {
  myservo2.attach(10); 

void loop() {
  for (pos = 0; pos <= -90; pos += 1) {
   
    myservo2.write(pos);             
    delay(10);                     
  }
  for (pos = -90; pos >= 0; pos -= 1) {
    myservo2.write(pos);             
    delay(10);                     
  }
}


so is that correct? and about the button i saw the code online but i dont know how to build it inside my code

slipstick

It's not a good idea wasting people's time with code you haven't even bothered trying to compile. You can't have two setup() and two loop() functions in one program.

OTOH if you put the "Servo myservo2" immediately below the original one and the second .attach() in the original setup() then that would be a start. Then you can just put the myservo2.write()s immediately below the original writes with a different value...and wvmarle has already told you what that value needs to be.

But at least try compiling and testing it before you come back again.

Steve


wvmarle

... and use code tags when posting code. As explained in the sticky.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Kilian03

ok thanks steve really appreaciate that ill try what you said

Kilian03


#include <Servo.h>

Servo myservo; 
Servo myservo2;

int pos = 0;   
void setup() {
  myservo.attach(9);
  myservo2.attach(10);

void loop() {
  for (pos = 0; pos <= 90; pos += 1) {
   
    myservo.write(pos);             
    delay(2);                     
  }
  for (pos = 90; pos >= 0; pos -= 1) {
    myservo.write(pos);             
    delay(10);                     
  }
}
void loop() {
  for (pos = 0; pos <= 90-; pos += 1) {
   
    myservo2.write(pos);             
    delay(10);
    }
  for (pos = 90-; pos >= 0; pos -= 1) {
    myservo2.write(pos);             
    delay(10);                     
  }
}

is this better now i was letting it verify but it tells me that something is wrong in the void set up function

MorganS

Use code tags,  as shown in the "how to use this forum" post.

Otherwise the forum software eats some of your code and we can't be sure what we see is exactly what you wrote.
"The problem is in the code you didn't post."

Go Up