input question

I wanted to use just a button connected to arduino, but I want him to give me data just after 4 seconds, and another data if I just push the button for 1 second, so if I push the button for five seconds I will have pin 12 on and if I push the button for 1 second I will have pin 11 on.

How can I do that?

How can I do that?

By writing code.

What is this data you want it to give?

Yes it can be done, but you need to look into simple timing codes. You press/hold the button, it stores the current millis(), (time) into a variable. Then using an IF statement, you look at the current time and subtract the stored time, all while comparing the difference to a Set time (5 seconds)

if(millis() - My_Time > 5000)
{
//done after 5 seconds have passed
}
else
{
// do something else or add more times to look at. EX 1 second, 2 seconds ... N seconds
}

If 4 seconds I want to turn pin 12 on and if 1 second turn pin 11 on.

thanks, I understood.

It´s already working, thank you very much HazardsMind!

I can´t make him turn off for after less than 3 seconds. Could someone tell me what am I doing wrong?

theres the code:

const int buttonPin = 2;
int led = 13;
int button = 0;

void setup() {

pinMode(led, OUTPUT);

pinMode(buttonPin, INPUT);
}

void loop(){

button = digitalRead(buttonPin);

if(millis()- button > 5000)
{
digitalWrite(led, HIGH);
}
if(millis() - button < 3000)
{
digitalWrite(led, LOW);
}
}

Why are you testing the difference between the current time and a pin's state?

That's kind of like subtracting walnuts from a brick wall.

When you're posting code, pleased use code tags, as was indicated in the threads at the top of the forum that you should have read.

You were told what to do but you haven't done it:-

You press/hold the button, it stores the current millis(), (time) into a variable.

You have to write the code for that as well. Use the time you recorded in your if statement.

ok, thanks