Delay()

From Microduino Wiki
Jump to: navigation, search
void delay (unsigned long ms)   

Delay (millisecond)

Delay, in milliseconds (1s is equal to 1000ms).


  • Warning:

The parameter is unsigned long, so when the delay parameter is over 32767(the largest value in in), suffix "UL" is needed to represent that it is an unsigned long integer, for example: delay(60000UL);.

Similarly, when there is an int in parameter expression, it need to be cast into unsigned long, 例for example: delay((unsigned long)tdelay * 100UL);.

  • Parameter

Set the corresponding LED of pin 13 as twinkling in 1s frequency:

int ledPin = 13;                 // LED connected to digital pin 13

void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()
{
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(1000);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(1000);                  // waits for a second
}

[Return to Arduino Syntax Manual]