Create a class PWMController that simulates a simple PWM output channel on a microcontroller.
The goal is to practice constructor overloading, state initialization, and safe parameter handling in Embedded C++.
Details you must implement
int frequency — PWM frequency in Hzint duty — duty cycle percentage (0–100)bool enabled — PWM output statePWMController(int freq)frequency = freqduty = 0enabled = falsePWMController(int freq, int dutyCycle)frequency = freqduty = dutyCycle, clamped to the range 0–100enabled = truevoid setDuty(int d)void disable()enabled = falsevoid print()F=<frequency> D=<duty> EN=<0 or 1>
Program flow (main())
modemode == 1freqPWMController using Constructor 1mode == 2freq and dutyPWMController using Constructor 2xx == -1, call disable()setDuty(x)print()
Example 1
Input:
1
1000
50 Output:
F=1000 D=50 EN=0
Example 2
Input:
2
2000 120
-1 Example Output
F=2000 D=100 EN=0
Constraints
0–100
Input
1 1000 50
Expected Output
F=1000 D=50 EN=0