Sunday, July 28, 2024

Servo test

 #include <Servo.h>


Servo myServo;  // Create a servo object to control a servo


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() {

  // Sweep the servo from 0 to 180 degrees

  for (pos = 0; pos <= 180; pos += 1) { 

    myServo.write(pos);              // Tell servo to go to position in variable 'pos'

    delay(15);                       // Wait 15 ms for the servo to reach the position

  }

  // Sweep the servo from 180 to 0 degrees

  for (pos = 180; pos >= 0; pos -= 1) { 

    myServo.write(pos);              // Tell servo to go to position in variable 'pos'

    delay(15);                       // Wait 15 ms for the servo to reach the position

  }

}


No comments:

Post a Comment

MUD Three Mode operation Manual Automatic GPS

 Code for three mode operation: /*   3-Mode Headlight Controller   - Manual mode (driver uses a toggle to pick high/low)   - Auto mode (LDR...