CCCPaste

"Servo Control" 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 Control"
	- Source Code NOT compiled for: Arduino Uno
	- Source Code created on: 2024-05-08 23:30:16

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* Improve user description requirement by specifying */
	/* EasyButton library usage for debouncing a push */
	/* button on pin D2 with INPUT_PULLUP configuration. */
/****** SYSTEM REQUIREMENT 2 *****/
	/* move the servo motor of 50° if the button is */
	/* pressed. */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 	// Include the EasyButton library for debouncing a push button
#include 		// Include the Servo library for controlling servo motor

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void moveServo(int degrees);

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t BUTTON_PIN = 2; // Define the pin for the push button (D2)

/***** DEFINITION OF SERVO MOTOR PIN *****/
const uint8_t SERVO_PIN = 9; // Define the pin for the servo motor

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
EasyButton button(BUTTON_PIN); // Create an EasyButton object for the push button
Servo servoMotor; // Create a Servo object to control the servo motor

void setup(void)
{
	// Initialize the EasyButton and Servo objects
	button.begin();
	servoMotor.attach(SERVO_PIN); // Attach the servo motor to the specified pin
}

void loop(void)
{
	// Read the button state
	button.read();

	// Move the servo motor 50 degrees if the button is pressed
	if (button.isPressed()) {
		moveServo(50);
	}
}

void moveServo(int degrees)
{
	servoMotor.write(degrees); // Move the servo motor to the specified angle
	delay(15); // Delay for stability
}

/* END CODE */