前言
VSCode 安裝Remote-SSH 配置好樹莓派
VSCode 自帶SSH控制檯
終端輸入命令
下載&安裝 net5
下載
wget https://dotnetcli.azureedge.net/dotnet/Sdk/5.0.205/dotnet-sdk-5.0.205-linux-arm.tar.gz 安裝 mkdir -p $HOME/dotnet && tar zxf dotnet-sdk-5.0.205-linux-arm.tar.gz -C $HOME/dotnet
安裝完畢後 建立demo
mkdir demo&cd demo dotnet new console -o demodev
ps bash: dotnet: command not found
如果報錯根據微軟docs文件,匯入環境變數
export DOTNET_ROOT=$HOME/dotnet export PATH=$PATH:$HOME/dotnet
先國際慣例 hello world!~
iot
新增iot庫 控制引腳 這庫使用BCM編碼17號 以下所有序號都是以BCM位置
dotnet add package System.Device.Gpio
using System; using System.Device.Gpio; using System.Threading; namespace demodev { class Program { static void Main(string[] args) { Console.WriteLine("Hello World! runtime pi"); var pin = 17; var lightTimeInMilliseconds = 500; var dimTimeInMilliseconds = 200; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"Let's blink an LED!"); using (GpioController controller = new GpioController()) { controller.OpenPin(pin, PinMode.Output); Console.WriteLine($"GPIO pin enabled for use: {pin}"); Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs eventArgs) => { controller.Dispose(); }; 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); } } } } }
dotnet run
ps:如果編譯不過同 得先 dotnet restore
總結
win10 敲程式碼 liunx直接 執行..這.....這也太爽了吧??? 期待VS也上這個功能 太需要了..