Beispiel #1
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();
        }
Beispiel #2
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();
        }
 public void Dispose()
 {
     redChannel.Dispose();
     greenChannel.Dispose();
     blueChannel.Dispose();
 }
 public void Dispose()
 {
     _redChannel.Dispose();
     _greenChannel.Dispose();
     _blueChannel.Dispose();
 }