using System; using System.IO; using System.Threading; using WiringPi; namespace WiringPiBrightnessByPwmAndButtonHold { internal class Program { private static void Main(string[] args) { var ci = File.ReadAllLines("/proc/cpuinfo"); foreach (var s in ci) Console.WriteLine(s); int ret = Init.WiringPiSetupGpio(); if (ret == -1) { Console.WriteLine("Init failed: {0}", ret); return; } const int buttonRightPin = 17; const int pwmPin = 18; const int buttonLeftPin = 27; const uint maxRange = 1000u; GPIO.pinMode(buttonLeftPin, (int)GPIO.GPIOpinmode.Input); GPIO.pinMode(buttonRightPin, (int)GPIO.GPIOpinmode.Input); GPIO.pinMode(pwmPin, (int)GPIO.GPIOpinmode.PWMOutput); GPIO.pwmSetClock(2); GPIO.pwmSetRange(maxRange); var v = 50; while (true) { var l = GPIO.digitalRead(buttonLeftPin); var r = GPIO.digitalRead(buttonRightPin); var step = 1; if (v > 50 && v <= 250) step = 5; if (v > 250) step = 25; if (v > 0 && l == 1) { if (v > 300) v -= step; else v -= step; GPIO.pwmWrite(pwmPin, v); } if (v < maxRange && r == 1) { if (v > 250) v += step; else v += step; GPIO.pwmWrite(pwmPin, v); } Console.WriteLine( $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}" + $" V={v} L={l} R={r}" ); Thread.Sleep(20); } } } }