/* -Name:
* -----------------------------------------------------------
* | Arduino Experimentation Kit Example Code |
* | CIRC-04 .: Sweep :. (Servo Motor Control) |
* -----------------------------------------------------------
*
*This is a simple program that sends a servo to a specific angle
*
* The challenge is outlined after the end of the program
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
int per ;
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(8, OUTPUT);
pinMode(5, OUTPUT);
}
void loop() {
if (pos = 0 ){
digitalWrite(8, HIGH);
delay(500);
digitalWrite(8, LOW);
Serial.println();
}
//digitalWrite(8, HIGH);
//delay(500);
//igitalWrite(8, LOW);
for(pos = 0; pos < 100; pos += 1)// goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
int per = 2.55 * pos;
analogWrite(5, per);
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 100; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
int per = 2.55 * pos;
analogWrite(5, per);
delay(15); // waits 15ms for the servo to reach the position
}
//digitalWrite(8, HIGH);
//delay(500);
//digitalWrite(8, LOW);
for(pos = 0; pos < 150; pos += 5) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
int per = 2.55 * pos;
analogWrite(5, per);
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 150; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
int per = 2.55 * pos;
analogWrite(5, per);
delay(15); // waits 15ms for the servo to reach the position
}
//digitalWrite(8, HIGH);
//delay(500);
//digitalWrite(8, LOW);
}
/* CHALLENGE:
* You will choose two different angles (not 180 degrees). In testing,
* the servo must visibly reach both angles.
* The servo will continually cycle between two different angles. First
* from zero degrees to Angle1 at one speed and back to zero at the same
* speed. Then from zero to Angle2 at a different speed and back to zero
* at that same speed.
* Add three different colour LEDs: white, red and green. White will
* indicate zero degrees, and the other two will indicate which Angle's
* cycle is happening.
* When at zero degrees, the white LED will blink on for 0.5 seconds.
* The other two LEDs will change brightness to match the percentage
* of angle. Off at zero degrees, maximum brightness when at the
* target angle, then back to off at zero degrees.
* NOTE: Float needs digits after decimal, can be 0