Arduino-Multi-line libraries Scoop application tasks

Source: Internet
Author: User
Tags sleep

Using the library's tasks feature, there are three things to do first:

First: Reference Library
#include "SCoop.h"
"Library File Download Address"
Http://www.dfrobot.com.cn/community/forum.php?mod=attachment&aid=MTI4MzZ8MWFmMjk1MGF8MTQ1MDcwNTA2M3wwfD

Https://share.weiyun.com/45420032c079bbf55a42f32d6a023ca2

Second: In the Setup function, call the Myscoop.start () command
void Setup () {
Myscoop.start ();
}

Third: In the loop function, the yield () command is called
void Loop () {
Yield ();
}

Then you can use "Tasks". There are two ways to define it, so keep looking down:
1, complete definition: Define "task" of the setup and loop two functions.
Define a task named "Tasktest":
Definetask (tasktest); Define a task with Definetask, named Tasktest
void Tasktest::setup ()//define the Setup () function for this task, which is used to initialize the settings.
{
Here is the contents of the task's setup function
}
void Tasktest::loop ()//Defines the loop () function for this task, which is used to loop through code execution.
{
Here is the contents of the Loop function of the task
}

2. Quick definition: Define only the loop function of the task
If the action performed in this thread does not require the initialization of setup, only the loop loop can be used to quickly define the thread task directly using Definetaskloop (), as follows:
Definetaskloop (TaskTest1)
{
Here is the contents of the Loop function of the task
}

Note that after you use this library, use Sleep (ms) as the delay, not delay ().
Because sleep (MS) is only for the current thread. and delay (MS) is for global.

Finally, a finished demo, 2 LEDs flashing at 100 milliseconds and 1 seconds respectively. Connect the LEDs to the 12 and 13 pins, then run the code to see the results.

#include "SCoop.h"
//Full definition
definetask (tasktest);
void Tasktest::setup ()
{
  pinmode (, OUTPUT);
}
void Tasktest::loop ()
{
  digitalwrite (+, high);
  Sleep (+);
  Digitalwrite (, low);
  Sleep (+);
}

Fast definition
Definetaskloop (TaskTest1)
{
  digitalwrite (n, high);
  Sleep (+);
  Digitalwrite (n, low);
  Sleep (+);
}

void Setup () {
  pinmode (OUTPUT);
  Myscoop.start ();
}

void Loop ()
{
  yield ();
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.