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-08-25 07:29:57

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* alla pressione del pulsante il servo si muove */
	/* dalla posizione 0% all 99% a passi del 5% ogni */
	/* 500ms, 0% corrisponde il massimo senso orario, 99% */
	/* il massimo senso antiorario. */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 	//https://github.com/arduino-libraries/Servo
#include 	//https://github.com/evert-arias/EasyButton

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void onPressed(void); // Function prototype for the button press callback

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t butt_PushButton_PIN_D12		= 12;

/***** DEFINITION OF PWM OUTPUT PINS *****/
const uint8_t servo_Servomotor_PWMSignal_PIN_D10		= 10;

/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
uint8_t	servo_Servomotor_PWMSignal_PIN_D10_rawData		= 0;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
// Instantiate the Servo object
Servo myServo; // Create a Servo object to control the servomotor

// Instantiate the EasyButton object
EasyButton button(butt_PushButton_PIN_D12); // Create an EasyButton object for the push button

void setup(void)
{
	Serial.begin(115200); // Initialize serial communication for debugging
	pinMode(butt_PushButton_PIN_D12, INPUT_PULLUP); // Set push button pin as input with pull-up resistor
	pinMode(servo_Servomotor_PWMSignal_PIN_D10, OUTPUT); // Set servomotor pin as output

	myServo.attach(servo_Servomotor_PWMSignal_PIN_D10); // Attach the Servo object to the PWM pin

	// Initialize the EasyButton
	button.begin(); // Initialize the button
	button.onPressed(onPressed); // Set the callback for when the button is pressed
}

// Callback function to be called when the button is pressed
void onPressed()
{
	Serial.println("Button pressed"); // Print message to Serial Monitor
	for (servo_Servomotor_PWMSignal_PIN_D10_rawData = 0; servo_Servomotor_PWMSignal_PIN_D10_rawData <= 99; servo_Servomotor_PWMSignal_PIN_D10_rawData += 5) {
		myServo.write(map(servo_Servomotor_PWMSignal_PIN_D10_rawData, 0, 99, 0, 180)); // Map 0-99 to 0-180 degrees
		delay(500); // Wait for 500ms before the next increment
	}
}

void loop(void)
{
	// Continuously read the status of the button
	button.read(); // Read the button state
}

/* END CODE */