Greenmunch will be at a trade show this weekend and I wanted to make an small, autonomous, arduino robot to show off some paper straws, so this is what I came up with, It consists of 1 Lego plate, 2 standard servos, 1 continuous servo, some paper straws, a bunch of wires and an arduino Uno. as you can see in the video, the potentiometer on the left controls the speed and direction of the continuous servo, and the potentiometer on the right controls the delay in between movements, or the overall movement speed of the standard servos.
here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
#include <Servo.h> Servo conservo; // create servo objects to control the servos Servo stdservo; Servo stdservo2; int potpin = 0; // analog pin used to connect the potentiometer int val; // variable to read the value from the analog pin int potpin2 = 1; int valu; void setup() { conservo.attach(9); // attaches the servo on pin 9 to the servo object stdservo.attach(10); stdservo2.attach(11); stdservo.write(55); stdservo2.write(60); delay(500); } void loop() { val = analogRead(potpin); // reads the value of the potentiometer (value between 20 and 1003) val = map(val, 20, 1003, 0, 180); // scale it to use it with the servo (value between 0 and 180) conservo.write(val); // sets the servo position according to the scaled value delay(5); // waits for the servo to get there valu = analogRead(potpin2); // reads the value of the potentiometer (value between 20 and 1003) valu = map(valu, 20, 1003, 100, 750); // scale it to use it with the servo (value between 100 and 750) stdservo.write(65); delay(valu); stdservo.write(75); delay(valu); stdservo.write(85); delay(valu); stdservo.write(95); delay(valu); stdservo2.write(70); delay(valu); stdservo2.write(80); delay(valu); stdservo2.write(90); delay(valu); stdservo2.write(100); // move the servos to the desired postitions with a delay delay(valu); // in between that is deteermined by a potentiometer stdservo.write(85); delay(valu); stdservo.write(75); delay(valu); stdservo.write(65); delay(valu); stdservo.write(55); delay(valu); stdservo2.write(90); delay(valu); stdservo2.write(80); delay(valu); stdservo2.write(70); delay(valu); stdservo2.write(60); delay(valu); } |