Ejemplo n.º 1
0
 public void TurnOffStrip()
 {
     Console.WriteLine("Turning off");
     _redChannel.Stop();
     _greenChannel.Stop();
     // _blueChannel.Stop();
 }
Ejemplo n.º 2
0
        protected override void Run()
        {
            _logger.LogTrace("Running LEDBreatheSoftware.cs");

            using (_pwmChannel)
            {
                _pwmChannel.Start();

                var cancellationTokenSource = new CancellationTokenSource(new TimeSpan(hours: 0, minutes: 0, seconds: 10));
                do
                {
                    _logger.LogTrace("Increasing brightness...");
                    for (int i = 0; i <= _frequency; i++)
                    {
                        _pwmChannel.DutyCycle = (double)i / _frequency;
                        Thread.Sleep(2);
                    }

                    _logger.LogTrace("Decreasing brightness...");
                    for (int i = _frequency; i >= 0; i--)
                    {
                        _pwmChannel.DutyCycle = (double)i / _frequency;
                        Thread.Sleep(2);
                    }
                } while (!cancellationTokenSource.Token.IsCancellationRequested);

                _pwmChannel.Stop();
            }
        }
Ejemplo n.º 3
0
 public void LedSoftPWMOff(CancellationToken cancellationToken)
 {
     lock (_locker)
     {
         IsRunning             = false;
         using PwmChannel _pwm = new SoftwarePwmChannel(_softpwmPin, frequency: 400, dutyCycle: 0);
         _pwm.Stop();
     }
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            using PwmChannel red   = new SoftwarePwmChannel(pinNumber: 18, frequency: 400, dutyCycle: 0);
            using PwmChannel green = new SoftwarePwmChannel(pinNumber: 23, frequency: 400, dutyCycle: 0);
            using PwmChannel blue  = new SoftwarePwmChannel(pinNumber: 24, frequency: 400, dutyCycle: 0);

            red.Start();
            green.Start();
            blue.Start();

            Breath(red, green, blue);

            red.Stop();
            green.Stop();
            blue.Stop();
        }
Ejemplo n.º 5
0
        protected override void Run()
        {
            _logger.LogTrace("Running RGBRandom.cs");

            var random = new Random(Guid.NewGuid().GetHashCode());

            _redPwmChannel.Start();
            _greenPwmChannel.Start();
            _bluePwmChannel.Start();

            _redPwmChannel.DutyCycle = 0.0;
            Thread.Sleep(500);
            _redPwmChannel.DutyCycle = 1.0;

            _greenPwmChannel.DutyCycle = 0.0;
            Thread.Sleep(500);
            _greenPwmChannel.DutyCycle = 1.0;

            _bluePwmChannel.DutyCycle = 0.0;
            Thread.Sleep(500);
            _bluePwmChannel.DutyCycle = 1.0;

            var cancellationTokenSource = new CancellationTokenSource(new TimeSpan(hours: 0, minutes: 0, seconds: 10));

            do
            {
                int red   = random.Next(0, 255);
                int green = random.Next(0, 255);
                int blue  = random.Next(0, 255);

                _logger.LogTrace("Changing the colour to R:{0} G:{1} B:{2}.", red, green, blue);
                _redPwmChannel.DutyCycle   = (double)((255 - red) * _multiplier) / _frequency;
                _greenPwmChannel.DutyCycle = (double)((255 - green) * _multiplier) / _frequency;
                _bluePwmChannel.DutyCycle  = (double)((255 - blue) * _multiplier) / _frequency;

                Thread.Sleep(500);
            } while (!cancellationTokenSource.IsCancellationRequested);

            _redPwmChannel.Stop();
            _greenPwmChannel.Stop();
            _bluePwmChannel.Stop();

            _redPwmChannel.Dispose();
            _greenPwmChannel.Dispose();
            _bluePwmChannel.Dispose();
        }
Ejemplo n.º 6
0
        public void Dispose()
        {
            LeftChannel.Stop();
            RightChannel.Stop();
            SetDefaults(gpio);

            gpio.ClosePin(FwL);
            gpio.ClosePin(BwL);

            gpio.ClosePin(FwR);
            gpio.ClosePin(BwR);

            gpio.ClosePin(STBY);

            LeftChannel.Dispose();
            RightChannel.Dispose();
            gpio.Dispose();
        }