In the code below i'm turning on the irled pin Then obviously turning it off for 500 ms.... i want know the default time my led will be on ???
digitalWrite(irled,HIGH);
digitalWrite(irled,LOW);
delay(500);
In the code below i'm turning on the irled pin Then obviously turning it off for 500 ms.... i want know the default time my led will be on ???
digitalWrite(irled,HIGH);
digitalWrite(irled,LOW);
delay(500);
The led will be on for about 2.5uS
Far too quick for anything.
Use the delay microseconds command between the on and the off statements.
The easy way is to use delayMicroseconds(100);
between turning it on and turning it off. Depending how accurate you want the timing to be you will need to tweak the parameter.
NOTE - during the delays nothing else can happen such as reading pins. There are ways round this though.
i want to readanlog pin reading during this delay period ???
Then it's time for you to look at the BlinkWithoutDelay example in the IDE.
Note the start time and check frequently whether the timing period is up. If yes then act on it, if no the do something else like reading a pin.
Approximately time of execution digitalWrite, or 4.7 usec
Assuming it is part of loop and HIGH is on?
void loop(){
digitalWrite(irled,HIGH);
digitalWrite(irled,LOW);
delay(500);
}
I'd go with Magician's number.
Did you want it on less? Use direct port manipulation, can be as low as 62.5nS:
Assume it starts off, with low output. To turn on & off again, say it was on PORTD bit 2 (i.e. D2):
PIND = 0b00000100; // toggle output PORTD bit 2 by writing 1 to input register bit
PIND = 0b00000100; // and back off again
@adeel - please don't "crosspost", that is put the same request in several places.
Topics merged.
i wanted my IR-led to turn on for about 100 us, and during that duration take the analog reading
Well as it takes 100uS to take an analogue reading simply do:-
void loop(){
digitalWrite(irled,HIGH);
val = analogRead(inputPin);
digitalWrite(irled,LOW);
// do something with the variable val
delay(500);
}