hi, i am working on a project in which frequency is constant and i have to vary duty cycle using arduino's serial monitor, i wrote this code which works perfect for an led but when i connect oscilloscope it doesnot show the correct frequency and duty cycle which i have input through serial monitor. here is my code, please help me
#include <PWM.h>
int led = 9;
int x=0;
void duty();
void setup()
{
pinMode(9, OUTPUT);
Serial.begin(9600); // Sets up communication with the serial monitor
duty();
}
void duty()
{
SetPinFrequency(led, 500);
}
void loop()
{
if (Serial.available()>0) // Checks for a character in the serial monitor
{
int x = Serial.parseInt();
Serial.println(x);
pwmWrite(led,x);
}
}