Components and supplies
Ice Cream Sticks
Arduino UNO
Servos (Tower Pro MG996R)
Project description
Code
The Code
c_cpp
1#include <Servo.h> 2 3Servo S1; 4Servo S2; 5Servo S3; 6Servo S4; 7 8int baud = 9600; 9int ledpin = 7; 10 11void setup() { 12 Serial.begin(baud); 13 14 S1.attach(3); 15 S2.attach(5); 16 S3.attach(6); 17 S4.attach(9); 18 19 pinMode(ledpin, OUTPUT); 20 21 for (int pos = 0; pos <= 30; pos += 1) { // goes from 0 degrees to 180 degrees 22 // in steps of 1 degree 23 S1.write(pos); // tell servo to go to position in variable 'pos' 24 delay(15); // waits 15ms for the servo to reach the position 25 } 26 for (int pos = 30; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees 27 S1.write(pos); // tell servo to go to position in variable 'pos' 28 delay(15); // waits 15ms for the servo to reach the position 29 } 30 for (int pos = 0; pos <= 30; pos += 1) { // goes from 0 degrees to 180 degrees 31 // in steps of 1 degree 32 S2.write(pos); // tell servo to go to position in variable 'pos' 33 delay(15); // waits 15ms for the servo to reach the position 34 } 35 for (int pos = 30; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees 36 S2.write(pos); // tell servo to go to position in variable 'pos' 37 delay(15); // waits 15ms for the servo to reach the position 38 } 39 for (int pos = 0; pos <= 30; pos += 1) { // goes from 0 degrees to 180 degrees 40 // in steps of 1 degree 41 S3.write(pos); // tell servo to go to position in variable 'pos' 42 delay(15); // waits 15ms for the servo to reach the position 43 } 44 for (int pos = 30; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees 45 S3.write(pos); // tell servo to go to position in variable 'pos' 46 delay(15); // waits 15ms for the servo to reach the position 47 } 48 for (int pos = 0; pos <= 30; pos += 1) { // goes from 0 degrees to 180 degrees 49 // in steps of 1 degree 50 S4.write(pos); // tell servo to go to position in variable 'pos' 51 delay(15); // waits 15ms for the servo to reach the position 52 } 53 for (int pos = 30; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees 54 S4.write(pos); // tell servo to go to position in variable 'pos' 55 delay(15); // waits 15ms for the servo to reach the position 56 } 57} 58 59void loop() { 60 61 //in this code the movments are looped for 1 time 62} 63
Comments
Only logged in users can leave comments
fmattiussi
0 Followers
•0 Projects
Table of contents
Intro
1
0