Skip to content

Commit 9cf724a

Browse files
committed
Added basic examples
1 parent 2b6742f commit 9cf724a

2 files changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Example 01: Ex_01_SayHello.ino
3+
* By: D. Aaron Wisner
4+
*
5+
* In this example we are creating a "SayHelloProcess" Class that prints "Hello from Process: 'id'" at a constant period
6+
*/
7+
8+
#include <ProcessScheduler.h>
9+
10+
// Create my custom process SayHelloProcess
11+
class SayHelloProcess : public Process
12+
{
13+
public:
14+
// Call the Process constructor
15+
SayHelloProcess(Scheduler &manager, ProcPriority pr, unsigned int period, int iterations)
16+
: Process(manager, pr, period, iterations) {}
17+
18+
protected:
19+
// Create our service routine
20+
virtual void service()
21+
{
22+
Serial.print("Hello from Process: ");
23+
Serial.println(getID());
24+
}
25+
};
26+
27+
Scheduler sched; // Create a global Scheduler object
28+
29+
// Create our high priority process that will get serviced as often as possible and run forever
30+
SayHelloProcess myProc(sched, HIGH_PRIORITY, SERVICE_CONSTANTLY, RUNTIME_FOREVER);
31+
32+
void setup()
33+
{
34+
Serial.begin(9600);
35+
// Add our process to the scheduler
36+
myProc.add();
37+
//enable it
38+
myProc.enable();
39+
}
40+
41+
void loop()
42+
{
43+
sched.run();
44+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Example 02: Ex_02_MultiBlink.ino
3+
* By: D. Aaron Wisner
4+
*
5+
* In this example we are creating a "BlinkProcess" Class that will toggle a pin at a constant period
6+
* We create 3 BlinkProcess objects that will blink at a diff. period and add them to the scheduler:
7+
* - blink250 (pin 13)
8+
* - blink500 (pin 12)
9+
* - blink1000 (pin 11)
10+
* Connect an LED to each of these pins and watch them blink
11+
*/
12+
13+
#include <ProcessScheduler.h>
14+
15+
// Create my custom Blink Process
16+
class BlinkProcess : public Process
17+
{
18+
public:
19+
// Call the Process constructor
20+
BlinkProcess(Scheduler &manager, ProcPriority pr, unsigned int period, int pin)
21+
: Process(manager, pr, period)
22+
{
23+
_pinState = LOW; // Set the default state
24+
_pin = pin; // Store the pin number
25+
}
26+
27+
protected:
28+
virtual void setup()
29+
{
30+
pinMode(_pin, OUTPUT);
31+
_pinState = LOW;
32+
digitalWrite(_pin, _pinState);
33+
}
34+
35+
// Undo setup()
36+
virtual void cleanup()
37+
{
38+
pinMode(_pin, INPUT);
39+
_pinState = LOW;
40+
}
41+
42+
// Create our service routine
43+
virtual void service()
44+
{
45+
// If pin is on turn it off, otherwise turn it on
46+
_pinState = !_pinState;
47+
digitalWrite(_pin, _pinState);
48+
}
49+
50+
private:
51+
bool _pinState; //the Current state of the pin
52+
int _pin; // The pin the LED is on
53+
};
54+
55+
Scheduler sched; // Create a global Scheduler object
56+
57+
// Create our blink processes
58+
BlinkProcess blink250(sched, HIGH_PRIORITY, 250, 13); // Blink 13 every 250 ms
59+
BlinkProcess blink500(sched, HIGH_PRIORITY, 500, 12); // Blink 12 every 500 ms
60+
BlinkProcess blink1000(sched, HIGH_PRIORITY, 1000, 11); // Blink 11 every 1000 ms
61+
62+
void setup()
63+
{
64+
// Add and enable our blink processes
65+
blink250.add(true); // Same as calling blink250.add() and blink250.enable();
66+
blink500.add(true);
67+
blink1000.add(true);
68+
}
69+
70+
void loop()
71+
{
72+
sched.run();
73+
}

0 commit comments

Comments
 (0)