variable pwm frequency and duty cycle using push buttons

hello, I need to vary the frequency and duty cycle in a pwm output using two buttons one to vary the frequency and another to vary the duty cycle, I am using a mega arduino 2560, searching here in the forum I found a similar topic where the following code:

#include <PWM.h>

int outputPin = 11;

//For testing
int freqInput = 100; //10-10000 Hz (I wanted that range only)
int dutyCycleInput = 70; //1-65535

void setup()

void loop()
//Get inputs from either serial or through pot
//So we have Frequency and Duty cycle in variables ‘freqInput’ & ‘dutyCycleInput’ respectively in int
SetPinFrequencySafe(outputPin, freqInput );
pwmWriteHR(outputPin, dutyCycleInput );

My question is how to add the buttons to vary both frequency and duty cycle in a single output? thanks

  1. Please go read the forum rules about how to properly post code. Find the "How to use this forum - Please read" thread. In programming and electronics stuff, it is always best to at least take a look at the rules and documentation before you start anything.

  2. Think a little about what details someone might need to help you. All you've said is that you want to vary the PWM frequency and duty cycle using a button. That isn't really enough to tell what you really want to do. Why don't you try again, use code tags this time, and say with some detail what you want.

How do you want to ‘vary’ the frequency with one button? Did you want to enter values in Morse code? Did you want the button to have several different meanings for single click, double click, and long press?

Same for duty-cycle.

Are you SURE you don’t want to use two pots?!?