Arduino

Reference Language | Libraries | Comparison | Changes

Scheduler

## yield()

#### Description

Passes control to other tasks when called. Ideally `yield()` should be used in functions that will take awhile to complete.

#### Syntax

yield();

#### Parameters

none

#### Returns

nothing

#### Example

#include <Scheduler.h>
int counter = 0;
int counter1 = 0;
void setup()
{
Serial.begin(9600);
Scheduler.startLoop(loop1);
}
void loop () {
analogWrite(9, counter);
counter++;
if (counter > 255){
counter = 0;
}
delay(33);
}
void loop1 () {
if (Serial.available()) {
char c = Serial.read();
if (c=='0') {
digitalWrite(2, LOW);
Serial.println("Led turned off!");
}
if (c=='1') {
digitalWrite(2, HIGH);
Serial.println("Led turned on!");
}
}
yield();
}
[Get Code]
Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

### Share

### This link has expired.
Please re-subscribe to our Newsletters.

### Subscribe to our Newsletters

Email

Please enter a valid email to subscribe

Arduino Newsletter
Arduino Store Newsletter

### Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy

###### Newsletter

- ©2015 Arduino
- Copyright Notice
- Contact us
- About us
- Careers