Im using the basic sweep sketch to have a servo motor sweep from 0 degrees to 30 and back with a 10ms delay for each sweep.
I want to use the millis() or delay() funtion in order to have the the servo sweep for only the first 10 minutes of every hour.
It doesnt have to be perfect on the milisecond, but I want it to at least function within a specific time frame.
Ive never used either the millis() or delay() function, so Im confused as to where to integrate either of them with the rest of the code or how to work with them.
code:
// Sweep
// This example code is in the public domain.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 30; pos += 1) // goes from 0 degrees to 30 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
for(pos = 30; pos>=1; pos-=1) // goes from 30 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
}