##マイクロソフト製のGPIOライブラリを使う
呼び出し方
using System.Device.Gpio;
GitにC#で書かれたLチカサンプルソースがあるので利用します。
サンプルソース
##RaspberryPiにNetCore 3.1をインストール
クリックした次に画面でパスをコピペできるのでパスを取得します
$ wget パス
$ mkdir -p $HOME/dotnet && tar zxf dotnet-sdk-3.1.100-linux-x64.tar.gz -C $HOME/dotnet
$ vim ~/.bashrc
#パスを追加する
export DOTNET_ROOT=$HOME/dotnet
export PATH=$PATH:$HOME/dotnet
#保存する
$ source ~/.bashrc
dotnetをパスを通します
##VisualStudioMacでコンソールアプリの開発



using System;
using System.Device.Gpio;
using System.Threading;
namespace led {
class Program {
static void Main(string[] args) {
//GPIOを番号を指定すること
int pin = 7;
GpioController controller = new GpioController();
controller.OpenPin(pin, PinMode.Output);
int lightTimeInMilliseconds = 1000;
int dimTimeInMilliseconds = 200;
while(true) {
Console.WriteLine($"Light for {lightTimeInMilliseconds}ms");
controller.Write(pin, PinValue.High);
Thread.Sleep(lightTimeInMilliseconds);
Console.WriteLine($"Dim for {dimTimeInMilliseconds}ms");
controller.Write(pin, PinValue.Low);
Thread.Sleep(dimTimeInMilliseconds);
}
}
}
}
##ビルド
dllを指定すると実行できます。exeに出力するやり方もあります。
$ dotnet led.dll
##ポイント
controller.OpenPin(pin, PinMode.Output) はGPIOを番号すること
##課題
リモートGPIOについて調べる
##VisualStudioMacで作成したプロジェクトファイルをMonoDevelopで開きデバッグする
MoNoDevelopにSDKのパスを設定する
###C#でのLチカ動作確認とれました。