Lab_interaccio/2015/Mariposa2_test/Mariposa2_test.ino
2025-02-25 21:29:42 +01:00

103 lines
5.1 KiB
C++

/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
Servo ala1; // create servo object to control a servo
// twelve servo objects can be created on most boards
Servo ala2; // create servo object to control a servo
// twelve servo objects can be created on most boards
Servo cabeza; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
const int paso = 1;
const int max_pos = 120;
const int min_pos = 30;
const int paso1 = 4;
const int max_pos1 = 130;
const int min_pos1 = 90;
void setup()
{
ala1.attach(9); // attaches the servo on pin 9 to the servo object
ala2.attach(10); // attaches the servo on pin 9 to the servo object
cabeza.attach(11); // attaches the servo on pin 9 to the servo object
}
void loop()
{
cabeza.write(100); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
for (int j=0; j<10; j++)
{
for(pos = min_pos; pos <= max_pos ; pos += paso) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
ala1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
ala2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = max_pos; pos>=min_pos ; pos-=paso) // goes from 180 degrees to 0 degrees
{
ala1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
ala2.write(pos); // tell servo to go to position in variable 'pos'
//myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
cabeza.write(20); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
for (int j=0; j<10; j++)
{
for(pos = min_pos1; pos <= max_pos1 ; pos += paso1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
ala1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
ala2.write(pos); // tell servo to go to position in variable 'pos'
// myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = max_pos1; pos>=min_pos1 ; pos-=paso1) // goes from 180 degrees to 0 degrees
{
ala1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
ala2.write(pos); // tell servo to go to position in variable 'pos'
//myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
cabeza.write(50); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
for (int j=0; j<10; j++)
{
for(pos = min_pos; pos <= max_pos ; pos += paso1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
ala1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
ala2.write(pos); // tell servo to go to position in variable 'pos'
// myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = max_pos; pos>=min_pos ; pos-=paso) // goes from 180 degrees to 0 degrees
{
ala1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
ala2.write(pos); // tell servo to go to position in variable 'pos'
//myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
}