I wanted to know how can I turn an analog input to output or a digital IO(without pwm)to pwm signals using arduino
You need to work on your question.
First: An analog input on arduino is "like" an voltage meter, instead of reading if the pin is HIGH (5V) or LOW (0V) it will measure the intermediate voltage.
Regarding the "without pwm IO" i think you mean "hardware PWM". Arduino have some pins that can candle hardware PWM (Arduino - AnalogWrite) and there are some libraries to use a "Software PWM" so you can use any IO (SoftPWM Library - Arduino Forum).
I think the question is how do you wanna translate between the analog value to the PWM? An example could be use a potentiometer to control a Servo like this:
Or using a potentiometer to control a led brightness.... or something else.... you need to explain what is your goal to actually help you...
Just want to turn any IO into PWM(not just dedicated pwm pinouts) life pin 36 of mega
Just want to turn any IO into PWM(not just dedicated pwm pinouts) life pin 36 of mega
yeah, that is typical arduino user
int number_of_points = 1024;
float duty_cycle = 0.5f;
int frequency =1;
int i = 0;
int temp = (int)number_of_points*duty_cycle;
while(1)
{
gpio_high();// Set gpio high, i don't know sintax for arduino
while(i<temp)
{
i++;
delay_us(frequency);
}
gpio_low();// Set gpio low, i don't know sintax for arduino
while(i<number_of_points)
{
i++;
delay_us(frequency);
}
i=0;
}
this is no way optimized, only to show the idea. with optimization it could make 10x higher frequency pwm signal