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: ESP32 DevKit V1
	- Source Code created on: 2024-07-25 11:10:03

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* stworz konsole w ktorej bedzie polecenie dzieki */
	/* ktoremu moge sterowac servo */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 	//https://github.com/deneyapkart/deneyap-servo-arduino-library

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

/***** DEFINITION OF PWM OUTPUT PINS *****/
const uint8_t servo_Servomotor_PWMSignal_PIN_D4		= 4;
const uint8_t servo_Servomotor_PWMSignal_PIN_D13		= 13;

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

/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float	servo_Servomotor_PWMSignal_PIN_D4_phyData		= 0.0;
float	servo_Servomotor_PWMSignal_PIN_D13_phyData		= 0.0;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
// Create Servo objects for each PWM signal pin
Deneyap_Servo servo1; // For pin D4
Deneyap_Servo servo2; // For pin D13

void setup(void)
{
	// Initialize serial communication for console commands
	Serial.begin(9600); // Start serial communication at 9600 baud rate

	// Attach the servo objects to their respective pins
	servo1.attach(servo_Servomotor_PWMSignal_PIN_D4);
	servo2.attach(servo_Servomotor_PWMSignal_PIN_D13);

	pinMode(servo_Servomotor_PWMSignal_PIN_D4,	 OUTPUT);
	pinMode(servo_Servomotor_PWMSignal_PIN_D13,	 OUTPUT);
}

void loop(void)
{
	// Check if data is available to read from the Serial Monitor
	if (Serial.available() > 0) {
		// Read the input value from the Serial Monitor
		int angle = Serial.parseInt(); // Parse the integer value

		// Ensure the angle is within the valid range for the servo
		if (angle >= 0 && angle <= 180) {
			// Update raw data for both servos
			servo_Servomotor_PWMSignal_PIN_D4_rawData = angle; // Set angle for servo1
			servo_Servomotor_PWMSignal_PIN_D13_rawData = angle; // Set angle for servo2
		} else {
			Serial.println("Invalid angle! Please enter a value between 0 and 180.");
		}
	}

	updateOutputs(); // Refresh output data
}

void updateOutputs()
{
	// Write the raw data to the servo objects
	servo1.write(servo_Servomotor_PWMSignal_PIN_D4_rawData);
	servo2.write(servo_Servomotor_PWMSignal_PIN_D13_rawData);
}

/* END CODE */