irriterande lådan

irriterande lådan william

#include <Servo.h> // include servo library
 
Servo myservo;  // create servo object to control a servo 
int pos = 0;    // variable to store the servo position 
boolean switchState = 0; // variable to store button state
 
void setup() 
{ 
  myservo.attach(9);  // pwm pin needed 
} 
 
void loop() 
{ 
int randdelay1 = random(15, 100);  // create a random delay between 15 and 100 each loop
int randdelay2 = random(15, 100);  // create a random delay between 15 and 100 each loop

  if(switchState == HIGH)          // check if switch is ON
  {
  for(pos = 10; pos <= 170; pos += 2) // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 5 degrees 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(randdelay1);               // waits a random time between rotation 
  } 
  for(pos = 170; pos>=10; pos-=2)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(randdelay2);               // waits a random time between rotation 
  } 
  }
  else          // else do nothing
  {
  }
} 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s