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 compiled for: Arduino Uno
	- Source Code created on: 2024-03-19 10:06:38

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* turns off the motor slowly if the speed level */
	/* exceeds above 300000 kmph */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include  // Include Servo library

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

/***** 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 Servo object

void setup(void)
{
  // put your setup code here, to run once:

  pinMode(motor_Servomotor_PWMSignal_PIN_D3, OUTPUT);
  myservo.attach(motor_Servomotor_PWMSignal_PIN_D3); // Attach Servo object to the pin

}

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

  /****** SYSTEM REQUIREMENTS *****/
  /****** SYSTEM REQUIREMENT 1 *****/
  /* turns off the motor slowly if the speed level */
  /* exceeds above 300000 kmph */
  
  if(motor_Servomotor_PWMSignal_PIN_D3_rawData > 300000) {
    motor_Servomotor_PWMSignal_PIN_D3_rawData = 180; // Set the servo position to maximum (turn off slowly)
  }

  updateOutputs(); // Refresh output data

}

void updateOutputs()
{
  motor_Servomotor_PWMSignal_PIN_D3_phyData = motor_Servomotor_PWMSignal_PIN_D3_rawData / 1023.0 * 180.0; // Transform raw data to physical data
  myservo.write(motor_Servomotor_PWMSignal_PIN_D3_phyData); // Use Servo object to set the position
}