Inputs question

I would like to put a selector, and each output go to an input of Arduino.

Input 1 = delay 300
Input 2 = delay 400
Input 3 = delay 500
etc...

and a switch.

Input 1 (delay 300); pres the swtich and output pin 12 it is set HIGH.

Can someone help me out? plissss!!!!

Show us what you have done so far.

Almost certainly you will be better not using the delay() function. Have a look at how millis() is used to manage timing in several things at a time.

It is much easier to design your program to use millis() than to convert from delay() to millis() at a later stage.

...R

I have this

int echoPin=7; // Pin Echo
int trigPin=8;// Pin Trigger
int LEDPin=10; // Pin LED

int maximo_rango = 450; //cm
int minimo_rango = 2; // cm
long duracion, distancia;

void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LEDPin, OUTPUT);
}

void loop() {

distancia=obtener_distancia();

if (distancia >= maximo_rango || distancia <= minimo_rango)
{
Serial.println("-1");
digitalWrite(LEDPin, LOW);
}
else {
Serial.println(distancia);
digitalWrite(LEDPin, HIGH);
}

delay(50);
}

long obtener_distancia(void)
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);

digitalWrite(trigPin, LOW);
duracion = pulseIn(echoPin, HIGH);

distancia = duracion/58.2;
return(distancia);

}

I have this because then I want to add the code switch.
give the function that if the sensor is not HIGH, even if you press the swtich 12 is LOW OUTPUT

LarryD:
Show us what you have done so far.

Robin2:
Almost certainly you will be better not using the delay() function. Have a look at how millis() is used to manage timing in several things at a time.

It is much easier to design your program to use millis() than to convert from delay() to millis() at a later stage.

...R

I knoww but I prefer the delay function for this case, thankssss

You have not clearly described what you want it to do, as far as I can tell.

What kind of input? pins being high/low? Serial data stream? Sensor readings?

What should it do in response to these inputs? Just pause for the stated number of milliseconds? You talk about it doing something to pin 12, but it's not clear what you want it to do to pin 12.

As far as I can tell looking at your code you have made no attempt to do what you're asking about, nor have you described what it is.

Adriansalguero:
I knoww but I prefer the delay function for this case, thankssss

That is not a good response - though per my comments above, I do not think you've even given us enough information to say whether or not delay is inappropriate (though it almost never is - I rarely have delay called in more than one or two places)

But when you say "I want help crossing this lake in my motorcycle" and we say "a motorcycle is not an appropriate vehicle for traveling on water, you should use a boat", your response shouldn't be "I knowww but I prefer a motorcycle"

I think it's easy to understand.

I want a switch connected to the digital inputs of Arduino, this switch will control the ignition timing of the pin 12, once you pressed the switch pin 12 will be put high.

Input 3 = 2000 milis
Input 4 = 5000
Input 6 = 7000

Only with funcion delay.

all this can ONLY happen if the sensor detected.

DrAzzy:
But when you say "I want help crossing this lake in my motorcycle" and we say "a motorcycle is not an appropriate vehicle for traveling on water, you should use a boat", your response shouldn't be "I knowww but I prefer a motorcycle"

Like this guy?

Adriansalguero:
I think it's easy to understand.

I want a switch connected to the digital inputs of Arduino, this switch will control the ignition timing of the pin 12, once you pressed the switch pin 12 will be put high.

Input 3 = 2000 milis
Input 4 = 5000
Input 6 = 7000

Only with funcion delay.

all this can ONLY happen if the sensor detected.

Well, sorry, but it is not obvious to me.

Do you meant that you have a 3 position selector switch and a momentary contact button switch

If the selector switch is at position 1 then pin 12 will go high for 2000 msecs when the button is pressed
If the selector switch is at position 2 then pin 12 will go high for 5000 msecs when the button is pressed
etc

and (if this is correct) I don't know what you mean by "ONLY happen if the sensor detected". Does that mean that there should be a test to see if a sensor (what sort of sensor) is attached before pin 12 is allowed to go HIGH ?

and (finally, for now) I don't understand what you mean by "Only with funcion delay."

I suspect that half of the work in creating a successful program is writing a clear and unambiguous description of the requirement

...R

OK, this is more or less what I want.

Is the ultrasonic sensor.

Adriansalguero:
OK, this is more or less what I want.

Is the ultrasonic sensor.

We might make some progress if you could respond to the posts that other make - sort of have a conversation.

You have not bothered to answer any of the questions that I took some trouble to write in Reply #8
If you don't understand my questions please say so, but don't ignore them.

...R

Adriansalguero:
OK, this is more or less what I want.

Is the ultrasonic sensor.

This is simply pointless.

Start making sense in English, or ask your questions in the Spanish section