I'm Having trouble using the fuction of arduino IDE ,as : my code is:-
const int led=13;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH);
delayMicroseconds(1000000);
digitalWrite(led, LOW);
delayMicroseconds(1000000);
}
[CODE/]
now, the code should make the led blink for 1 second , just like the blink code ,
but my led is constantly onn ! it dosen't blink ,its just on... help me ASAP ..
Thanks ;)
what you should do is use delay() and delayMicroseconds()
For example, you want to delay 500.017 milliseconds. what you do is delay(500); delayMicroseconds(17);
for a more general case you could get the milliseconds and microseconds like this:
float t = 500.017;
int x = (int) t*1000; // here you get 500017
int milli = x / 1000; // you get 500
int micro = x % 1000; // you get 017
delay(milli);
delayMicroseconds(micro);
Please not that all this computation takes time to execute, so the extra precision you are getting from using microseconds is probably lost with the overhead of these calculations. It tried this once, and ended up using just milliseconds...