-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
76 lines (63 loc) · 2.2 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
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Device.Gpio;
using System.Threading;
using System.IO.Ports;
using System.Threading.Tasks;
// using System.Device.Spi;
// using System.Device.Spi.Drivers;
namespace gpiotest
{
class Program
{
static async Task Main(string[] args)
{
var pin1 = 17;
var pin2 = 18;
bool flag = true;
try
{
var serport = new SerialPort()
{
PortName = "/dev/serial0",
BaudRate = 9600,
Parity = Parity.None,
DataBits = 8,
StopBits = StopBits.One
};
serport.Open();
using (var controller = new GpioController())
{
controller.OpenPin(pin1, PinMode.Output);
Console.WriteLine($"GPIO pin configured for output: {pin1}");
controller.OpenPin(pin2, PinMode.Output);
Console.WriteLine($"GPIO pin configured for output: {pin2}");
Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs eventArgs) =>
{
controller.Dispose();
};
while (true)
{
if (flag)
{
controller.Write(pin1, PinValue.Low);
controller.Write(pin2, PinValue.High);
Console.WriteLine($"Pin {pin1} Low, Pin {pin2} High");
}
else
{
controller.Write(pin1, PinValue.High);
controller.Write(pin2, PinValue.Low);
Console.WriteLine($"Pin {pin1} High, Pin {pin2} Low");
}
flag = !flag;
await Task.Delay(1000);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Exception: {ex.Message}");
}
}
}
}