Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
#include <Servo.h> Servo right;Servo left;int pos = 0;void setup() { right.attach(9); left.attach(10);} void loop() { for(pos = 0; pos < 360; pos += 5) { right.write(pos); delay(15); } for(pos = 0; pos < 360; pos -= 5) { right.write(pos); delay(15); }}
pos += 5
pos++
If I change the Red and Black wires around, will my servo move the other way?
#include <Servo.h> Servo right;Servo left;int pos = 0;void setup() { right.attach(9); left.attach(10);unsigned int leftposition = 0;unsigned int rightposition = 360;unsigned byte leftflag = 0;unsigned byte rightflag = 1;} void loop() { insigned int looper = 1000;while(looper >= 0){if(leftflag == 0){leftposistion+=5;if (leftposition >= 360){leftflag = 1;}if(rightflag == 0){rightposistion+=5;if (rightposition >= 360){rightflag = 1;}if(leftflag == 1){leftposistion-=5;if (leftposition <= 0){leftflag = 0;}if(rightflag == 1){rightposistion-=5;if (rightposition <= 0){rightflag = 0;}right.write(rightposition);left.write(leftposition); delay(50);}looper--;} }
#include <Servo.h> Servo right;Servo left;int pos = 0;void setup() { right.attach(9); left.attach(10);int leftposition = 0;int rightposition = 360;int leftflag = 0;int rightflag = 1;} void loop() { int looper = 1000;while(looper >= 0){if(leftflag == 0){leftposistion += 5;if (leftposition >= 360){leftflag = 1;}if(rightflag == 0){rightposistion+=5;if (rightposition >= 360){rightflag = 1;}if(leftflag == 1){leftposistion-=5;if (leftposition <= 0){leftflag = 0;}if(rightflag == 1){rightposistion-=5;if (rightposition <= 0){rightflag = 0;}right.write(rightposition);left.write(leftposition); delay(50);}looper--;} }
int leftflag = 0;int rightflag = 1;
#include <Servo.h> Servo right;Servo left;int pos = 0;void setup() { right.attach(9); left.attach(10);} void loop() {int leftposition = 0;int rightposition = 360;int leftflag = 0;int rightflag = 1;int looper = 1000;while(looper >= 0){if(leftflag == 0){leftposition += 5;if (leftposition >= 360){leftflag = 1;}if(rightflag == 0){rightposition+=5;if (rightposition >= 360){rightflag = 1;}if(leftflag == 1){leftposition-=5;if (leftposition <= 0){leftflag = 0;}if(rightflag == 1){rightposition-=5;if (rightposition <= 0){rightflag = 0;}right.write(rightposition);left.write(leftposition); delay(50);}looper--;} }
#include <Servo.h> Servo right;Servo left;int pos = 0;void setup() { right.attach(9); left.attach(10);} void loop() {int leftposition = 0;int rightposition = 360;int leftflag = 0;int rightflag = 1;int looper = 1000;while(looper >= 0){if(leftflag == 0){leftposition += 5;if (leftposition >= 360){leftflag = 1;}if(rightflag == 0){rightposition+=5;if (rightposition >= 360){rightflag = 1;}if(leftflag == 1){leftposition-=5;if (leftposition <= 0){leftflag = 0;}if(rightflag == 1){rightposition-=5;if (rightposition <= 0){rightflag = 0;}right.write(rightposition);left.write(leftposition); delay(50);} //DELETE THIS BRACKET!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!looper--;} }