-
Notifications
You must be signed in to change notification settings - Fork 586
/
Program.cs
55 lines (45 loc) · 1.39 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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
using System.Threading;
using Iot.Device.Button;
// Initialize a new button with the corresponding button pin
GpioButton button = new(buttonPin: 37);
Debug.WriteLine("Button is initialized, starting to read state");
// Enable or disable holding or doublepress events
button.IsDoublePressEnabled = true;
button.IsHoldingEnabled = true;
// Write to debug if the button is down
button.ButtonDown += (sender, e) =>
{
Debug.WriteLine($"buttondown IsPressed={button.IsPressed}");
};
// Write to debug if the button is up
button.ButtonUp += (sender, e) =>
{
Debug.WriteLine($"buttonup IsPressed={button.IsPressed}");
};
// Write to debug if the button is pressed
button.Press += (sender, e) =>
{
Debug.WriteLine($"Press");
};
// Write to debug if the button is double pressed
button.DoublePress += (sender, e) =>
{
Debug.WriteLine($"Double press");
};
// Write to debug if the button is held and released
button.Holding += (sender, e) =>
{
switch (e.HoldingState)
{
case ButtonHoldingState.Started:
Debug.WriteLine($"Holding Started");
break;
case ButtonHoldingState.Completed:
Debug.WriteLine($"Holding Completed");
break;
}
};
Thread.Sleep(Timeout.Infinite);