forked from steffalk/AbstractIO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSample02SmoothBlinker.cs
40 lines (36 loc) · 1.12 KB
/
Sample02SmoothBlinker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Threading;
namespace AbstractIO.Samples
{
/// <summary>
/// Lets a lamp blink smoothly by slowly increasing or decreasing its brightness.
/// </summary>
public static class Sample02SmoothBlinker
{
/// <summary>
/// Runs the sample.
/// </summary>
/// <param name="lamp">The lamp, as an analog output.</param>
public static void Run(ISingleOutput lamp)
{
// Check parameters:
if (lamp == null) throw new ArgumentNullException(nameof(lamp));
// Smoothly blink the output:
const int Steps = 10;
const int PauseInMs = 50;
while (true)
{
for (int step = 0; step < Steps; step++)
{
lamp.Value = (float)step / (float)Steps;
Thread.Sleep(PauseInMs);
}
for (int step = Steps; step > 0; step--)
{
lamp.Value = (float)step / (float)Steps;
Thread.Sleep(PauseInMs);
}
}
}
}
}