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-06-20 17:49:26

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* szervó motor seriallal való vezérlése */
/****** END SYSTEM REQUIREMENTS *****/

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

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

/***** DEFINITION OF PWM OUTPUT PINS *****/
const uint8_t motor_Servomotor_PWMSignal_PIN_D3 = 3;

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

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

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
Servo myservo;  // Create a Servo object

void setup(void)
{
    // put your setup code here, to run once:
    myservo.attach(motor_Servomotor_PWMSignal_PIN_D3);  // Attach the servo to pin 3
    pinMode(motor_Servomotor_PWMSignal_PIN_D3, OUTPUT);
    Serial.begin(9600);  // Initialize serial communication at 9600 bits per second
}

void loop(void)
{
    // put your main code here, to run repeatedly:
    if (Serial.available() > 0) {
        int input = Serial.parseInt();  // Read the incoming integer from the serial buffer
        if (input >= 0 && input <= 180) {
            motor_Servomotor_PWMSignal_PIN_D3_rawData = input;  // Update the raw data with the received value
        }
    }
    updateOutputs(); // Refresh output data
}

void updateOutputs()
{
    myservo.write(motor_Servomotor_PWMSignal_PIN_D3_rawData);  // Write the raw data to the servo
    delay(15);  // Small delay to allow the servo to move
}

/* END CODE */