RSS RSS print

Materiály k výučbe pre SŠ

Programovanie mikrokontroléra Arduino

Servo

#include <Servo.h>

Servo myservo;  // 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

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 45; pos <= 135; pos += 1) { // goes from 45 degrees to 135 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 135; pos >= 45; pos -= 1) { // goes from 135 degrees to 45 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

 

Bzučiak

void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  tone(13, 440);  //start tone on frequency 440 Hz
  delay(1000);    //wait 1 second
  noTone(13);     //stop tone
  delay(1000);    //wait 1 second
}

 

Robot 1 softver

stiahnuť

 

 

 

 

=