/********* 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: ESC Control
	- Source Code NOT compiled for: Arduino Nano
	- Source Code created on: 2024-10-19 13:47:26

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* code to control two escs connected to specify */
	/* pins, start with calibration and arming for 30s */
	/* then run the motors for 45s with 50% of speed */
	/* after that turn off the motors */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include <ESC.h>	// https://github.com/RB-ENantel/RC_ESC

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

/***** DEFINITION OF PWM OUTPUT PINS *****/
const uint8_t esc1_PIN_D6 = 6; // Pin for ESC1
const uint8_t esc2_PIN_D9 = 9; // Pin for ESC2

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

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

/****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
ESC esc1(esc1_PIN_D6, 1000, 2000, 500);  // Instance for ESC1 on pin D6
ESC esc2(esc2_PIN_D9, 1000, 2000, 500);  // Instance for ESC2 on pin D9

void setup(void)
{
	// Initialize PWM output pins
	pinMode(esc1_PIN_D6, OUTPUT);
	pinMode(esc2_PIN_D9, OUTPUT);
  
	// Calibrate ESCs
	esc1.calib();
	esc2.calib();
  
	// Stop ESCs after calibration
	esc1.stop();
	esc2.stop();

	// Arm ESCs for 30 seconds
	esc1.arm();
	esc2.arm();
	delay(30000); // Wait for 30 seconds
}

void loop(void)
{
	// Set speed to 50% for 45 seconds
	esc1.speed(1500); // 50% speed for ESC1
	esc2.speed(1500); // 50% speed for ESC2
	delay(45000); // Wait for 45 seconds

	// Turn off motors
	esc1.stop();
	esc2.stop();

	// Stop loop execution
	while (true); // Stop further execution
}

/* END CODE */