Using a push button to set value of an int

I have a nano running a wave form 10ms on 95 ms off
I want to incorparate a push button so when I push it it changes the on off times
so before its pressed TON =10 toff =90
when I push the putton ton changes to 5 and toff to 95.

Can I use an if else statement to do this
ie if( pushbutton==HIGH);
Ton =10;
Toff =90;

Would this be the correct way to do it?

That says so long as the button is held HIGH you get 10/90, once you let go it becomes 5/95. If that's what you meant then it's fine.

But more likely you mean that each time you press and release the values will change. If so you need to look at the StateChangeDetection example in the IDE. You need to know when the button BECOMES pressed not just IS pressed.


That is what I want it I press the putton and hold it ,it changes.
This is my code it compiles ok but what ever the state of the pushbutton pin is the value stays at 10, never =50 .
I can't work out why

int Output =3;

int OutputState=LOW;
unsigned long previousMillis1=0;
long OnTime;// on time of waveform

long OffTime;// off time of waveform
int pushbutton=6

void setup() {
// put your setup code here, to run once:


void loop() {
// put your main code here, to run repeatedly:
unsigned long currentMillis=millis();
if (pushbutton==HIGH

}else {

OnTime =10;
OffTime= 90;

if ((OutputState==HIGH)&&(currentMillis-previousMillis1>=OnTime))
OutputState =LOW;
else if ((OutputState==LOW)&&(currentMillis-previousMillis1>=OffTime))

I assume your button is wired to pin 6, in which case you should replace the following:

if (pushbutton==HIGH)


if (digitalRead(pushbutton) == HIGH)

How is your pushbutton wired? The way you have the pin configured and the way you are testing the input value implies you have the button wired to +5V with a pulldown resistor. Is this the case?

You say:
pushbutton is the number = 6
you never check its state by asking digitalRead()

Please check this basic tutorial here:

this solves your problem

Great thanks for your help . It now works