-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMeadowApp.cs
75 lines (67 loc) · 2.03 KB
/
MeadowApp.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
65
66
67
68
69
70
71
72
73
74
75
using Meadow;
using Meadow.Devices;
using Meadow.Hardware;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Walking_DigitalOutputs;
public class MeadowApp : App<F7FeatherV2>
{
IList<IDigitalOutputPort> _outs = new List<IDigitalOutputPort>();
IList<string> _outChans = new List<string>();
public override async Task Run()
{
while (true)
{
// create all our digital output ports
ConfigureOutputs();
// turn them on/off
await WalkOutputs();
// tear down
DisposePorts();
}
}
void ConfigureOutputs()
{
foreach (var pin in Device.Pins.AllPins)
{
Resolver.Log.Info("Found pin: " + pin.Name);
foreach (var channel in pin.SupportedChannels)
{
Resolver.Log.Info("Contains " + channel.Name + "channel.");
// if it's a digital channel, create a port.
if (channel is IDigitalChannelInfo
&& !(channel is ICommunicationChannelInfo)
&& !(channel is IPwmChannelInfo)
)
{
if (!_outChans.Contains(channel.Name))
{
_outs.Add(Device.CreateDigitalOutputPort(pin));
}
else
{
Resolver.Log.Info("Cannot add pin " + pin.Name + ", as the digital channel, " + channel.Name + " exists on another pin");
}
}
}
}
}
async Task WalkOutputs()
{
// turn each one on for a bit.
foreach (var port in _outs)
{
port.State = true;
await Task.Delay(250);
port.State = false;
}
}
void DisposePorts()
{
foreach (var port in _outs)
{
port.Dispose();
}
_outs.Clear();
}
}