-
라즈베리파이5 C#으로 LED제어 부터 Docker 까지카테고리 없음 2024. 2. 13. 07:40
Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env WORKDIR /App # Copy everything COPY . ./ # Restore as distinct layers RUN dotnet restore # Build and publish a release RUN dotnet publish -c Release -o out # Build runtime image FROM mcr.microsoft.com/dotnet/aspnet:8.0 WORKDIR /App COPY --from=build-env /App/out . RUN apt-get update RUN apt-get -y install libgpiod-dev ENTRYPOINT ["dotnet", "BlinkTutorial.dll"]
Program.cs
using System.Device.Gpio; Console.WriteLine("Blinking LED. Press Ctrl+C to end."); using var controller = new GpioController(); int outPin = 24; controller.OpenPin(outPin, PinMode.Output); Task task = Task.Factory.StartNew(() => { while (true) { controller.Write(outPin, PinValue.High); Thread.Sleep(100); controller.Write(outPin, PinValue.Low); } }); Console.ReadLine();