/********* 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: "Sine PWM Setup"
	- Source Code compiled for: Arduino Mega
	- Source Code created on: 2024-01-20 11:19:13

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* 3 sine  pwm to inverter  with 120 degree phase */
	/* shift change the  frequency  of output wave? */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include <Arduino.h>

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

/***** DEFINITION OF ANALOG INPUT PINS *****/
const uint8_t j_Potentiometer_Vout_PIN_A0 = A0;
const uint8_t j_Potentiometer_Vout_PIN_A1 = A1;

// Constants for PWM output pins
const uint8_t PWM_PIN_1 = 2;
const uint8_t PWM_PIN_2 = 3;
const uint8_t PWM_PIN_3 = 4;

void setup(void)
{
  // put your setup code here, to run once:
  
  /* 3 sine pwm to inverter with 120 degree phase shift */
  
  // Configure analog input pins as inputs
  pinMode(j_Potentiometer_Vout_PIN_A0, INPUT);
  pinMode(j_Potentiometer_Vout_PIN_A1, INPUT);

  // Configure PWM output pins as outputs
  pinMode(PWM_PIN_1, OUTPUT);
  pinMode(PWM_PIN_2, OUTPUT);
  pinMode(PWM_PIN_3, OUTPUT);
}

void loop(void)
{
  // put your main code here, to run repeatedly:
  
  /* change the frequency of output wave? */
  
  // Read the potentiometer values
  int potValue1 = analogRead(j_Potentiometer_Vout_PIN_A0);
  int potValue2 = analogRead(j_Potentiometer_Vout_PIN_A1);

  // Convert potentiometer values to PWM duty cycles (0-255 range)
  int dutyCycle1 = map(potValue1, 0, 1023, 0, 255);
  int dutyCycle2 = map(potValue2, 0, 1023, 0, 255);

  // Set the PWM duty cycles for the output pins
  analogWrite(PWM_PIN_1, dutyCycle1);
  analogWrite(PWM_PIN_2, dutyCycle2);
  analogWrite(PWM_PIN_3, dutyCycle1 + dutyCycle2);
}
