# Need help!

There is 2 button , button1 and button2, 3 different modes, modeA ,modeB and modeC. Default mode will be modeA it will change to modeB if button1 is press. While in modeB if button2 is press within 10second, it will revert back to modeA, if not i will go to mode C after 10second. The program has to run continuously.

There is 2 button , button1 and button2, 3 different modes, modeA ,modeB and modeC. Default mode will be modeA it will change to modeB if button1 is press. While in modeB if button2 is press within 10second, it will revert back to modeA, if not i will go to mode C after 10second. The program has to run continuously.

And?

And?

I would speculate that when the OP says Need help!, he or she actually means Can someone do my school project for me!

But that's purely idle speculation on my part.

I need a example for me to understand as i have been stuck at this algorithm for weeks and unable to get a solution.

LowInt:
I need a example for me to understand as i have been stuck at this algorithm for weeks and unable to get a solution.

Did those weeks of work result in any code? Now would be a good time to post it.

Most people here will want to know what you have tried so far.

``````int button1= 3;
int button2= 4;
int led1 = 5;
int led2 = 6;
int led3 = 7;

void setup(){
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(button1,INPUT);
pinMode(button2,INPUT);
Serial.begin(9600);
}
void loop(){
// Don't know what should i be using.
}
void modeA
{
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
}

void modeB
{
digitalWrite(led1,HIGH);
digitalWrite(led3,HIGH);
}

void modeC
{
digitalWrite(led2,HIGH);
digitalWrite(led3,HIGH);
}
``````

Have you wired switches to the relevant input pins? If so, how are they wired?

Your code doesn't enable the internal pull-up resistors, so you'd need to use external pull-up/pull-down resistors. I suggest you enable the internal pull-ups instead to save having to add the external resistors.

Have you looked at and run any of the standard example sketches? There are some that show how to read the state of a digital input and detect button presses, which will be the first thing you need to do.

Start simple, example that treats the buttons as toggle switches:

``````// change pinModes:
pinMode(button1, INPUT_PULLUP);  //pin with internal pullup, reads HIGH unless grounded
pinMode(button2, INPUT_PULLUP);

void loop(){
// Don't know what should i be using.
modeA();
}
modeB();
}

modeC();
}

modeD();
}

} // end loop
``````

Should give you some ideas. Your mode(s) only turn on LEDs, need to add some code to turn LEDs off too, otherwise all will end up on all the time very quickly.