-
Notifications
You must be signed in to change notification settings - Fork 598
/
Copy pathProgram.cs
64 lines (52 loc) · 1.66 KB
/
Program.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Threading;
using Iot.Device.Multiplexing;
// This sample is configured to use 8 leds, but can be changed to a use different number.
// To use with (8) directly connected GPIO pins
int[] pins = new int[] { 4, 17, 27, 22, 5, 6, 13, 19 };
using IOutputSegment segment = new GpioOutputSegment(pins);
// To use with charlieplexing
// int[] pins = new int[] { 4, 17, 27, 22};
// using IOutputSegment segment = new CharlieplexSegment(pins, 8);
// To use a shift register
// using IOutputSegment segment = new ShiftRegister(ShiftRegisterPinMapping.Minimal, 8);
using AnimateLeds leds = new(segment);
CancellationTokenSource cts = new();
CancellationToken token = cts.Token;
Console.CancelKeyPress += (s, e) =>
{
e.Cancel = true;
cts.Cancel();
int delay = leds.LitTime + 10;
leds.DimTime = 10;
leds.LitTime = 10;
Thread.Sleep(delay);
};
Console.WriteLine($"Animate! {segment.Length} pins are initialized.");
while (!token.IsCancellationRequested)
{
Console.WriteLine($"Lit: {leds.LitTime}ms; Dim: {leds.DimTime}");
leds.FrontToBack(token, true);
leds.BacktoFront(token);
leds.MidToEnd(token);
leds.EndToMid(token);
leds.MidToEnd(token);
leds.LightAll(token);
leds.DimAllAtRandom(token);
if (token.IsCancellationRequested)
{
break;
}
else if (leds.LitTime < 20)
{
leds.ResetTime();
}
else
{
leds.LitTime = (int)(leds.LitTime * 0.7);
leds.DimTime = (int)(leds.DimTime * 0.7);
}
}
segment.Dispose();