Hi!
I didn't quite understand one thing, the frequency of a PWM pin on the Arduino Uno is 500Hz, and the period T = 1 / Freq = 2 milliseconds. For a PWM signal for example 64 (max is 255) does it mean 64 pulses applied to the output pin with a period of 2 milliseconds? Or is the total period of the PWM signal with the value 64?
Below I have a small program for controlling the light intensity of an LED using a potentiometer.
int potPin = A0;
int control = 0;
int PWM = 0;
void setup() {
pinMode(potPin, INPUT);
Serial.begin(9600);
}
void loop() {
control = analogRead(potPin);
PWM = map(control, 0, 1023, 0 , 255);
Serial.print("Analog value: ");
Serial.print(control);
Serial.print("Pwm value: ");
Serial.println(PWM);
//Serial.print("Duty Cycle in % is...")
}
How do I calculate duty cycle in % percent?
I accessed a few links but I don't know how to implement on my code.
https://create.arduino.cc/projecthub/boaz/duty-cycle-calculator-and-frequency-meter-f4d763