forked from sharpbrick/powered-up
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleTechnicColorSensor.cs
42 lines (30 loc) · 1.52 KB
/
ExampleTechnicColorSensor.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
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using SharpBrick.PoweredUp;
namespace Example;
public class ExampleTechnicColorSensor : BaseExample
{
public override async Task ExecuteAsync()
{
using var hub = Host.FindByType<TechnicMediumHub>();
await hub.VerifyDeploymentModelAsync(modelBuilder => modelBuilder
.AddHub<TechnicMediumHub>(hubBuilder => hubBuilder
.AddDevice<TechnicColorSensor>(hub.A)
)
);
var technicColorSensor = hub.A.GetDevice<TechnicColorSensor>();
var m1 = technicColorSensor.ColorObservable.Subscribe(x => Log.LogWarning($"Color: {x}"));
var m2 = technicColorSensor.ReflectionObservable.Subscribe(x => Log.LogWarning($"Reflection: {x}"));
var m3 = technicColorSensor.AmbientLightObservable.Subscribe(x => Log.LogWarning($"Ambient Light: {x}"));
var m6 = technicColorSensor.RgbObservable.Subscribe(x => Log.LogWarning($"RGB: {x.red}/{x.green}/{x.blue}/{x.fourthValue}"));
var m7 = technicColorSensor.HsvObservable.Subscribe(x => Log.LogWarning($"RGB: {x.hue}/{x.saturation}/{x.value}"));
await technicColorSensor.SetupNotificationAsync(technicColorSensor.ModeIndexColor, true);
await Task.Delay(20_000);
// set only subset of the lights
await technicColorSensor.SetSectorLightAsync(0, 0, 100);
//await technicColorSensor.SetRgbColors2Async(100, 0, 0);
await Task.Delay(5_000);
await hub.SwitchOffAsync();
}
}