Delay()

From Microduino Wiki
Revision as of 02:30, 17 August 2016 by Fengfeng (talk) (Created page with "<pre style="color:green"> void delay (unsigned long ms) </pre> Delay (millisecond) <br> Delay, in milliseconds (1s is equal to 1000ms).<br> *'''Warning''':<br> The para...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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]