CCCPaste

"Servo Swap" rev_01

/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: "Servo Swap"
	- Source Code compiled for: Arduino Nano
	- Source Code created on: 2023-12-28 06:12:16

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* i want to attach two servo to swap in opposite */
	/* direction */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 
#include 

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF PWM OUTPUT PINS *****/
const uint8_t servo1_PIN = 3;
const uint8_t servo2_PIN = 5;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
Servo servo1;
Servo servo2;

void setup(void)
{
  // put your setup code here, to run once:
  pinMode(servo1_PIN, OUTPUT);
  pinMode(servo2_PIN, OUTPUT);

  servo1.attach(servo1_PIN); // Attaching servo1 to pin D3
  servo2.attach(servo2_PIN); // Attaching servo2 to pin D5
}

void loop(void)
{
  // put your main code here, to run repeatedly:

  // Swap the servo positions in opposite directions
  for (int angle = 0; angle <= 180; angle++) {
    servo1.write(angle);
    servo2.write(180 - angle);
    delay(15); // Adjust the delay according to your requirements
  }
}