Exemplo n.º 1
0
 public void TurnOnStrip()
 {
     Console.WriteLine("Turning on");
     _redChannel.Start();
     _greenChannel.Start();
     //_blueChannel.Start();
 }
Exemplo 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();
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            SoftwarePwmChannel pwmChannel = null;

            Console.WriteLine("Hello PWM!");
            //注册退出事件
            Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs eventArgs) =>
            {
                Console.WriteLine("\nPWM Exit!");
            };
            try
            {
                using (pwmChannel = new SoftwarePwmChannel(17))
                {
                    pwmChannel.Start();
                    for (double fill = 0.0; fill <= 1.0; fill += 0.01)
                    {
                        pwmChannel.DutyCycle = fill;
                        Thread.Sleep(300);
                    }
                    for (double fill = 1.0; fill >= 0.0; fill -= 0.01)
                    {
                        pwmChannel.DutyCycle = fill;
                        Thread.Sleep(300);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 4
0
        public RgbLed(int redPin = 4, int greenPin = 19, int bluePin = 6)
        {
            redChannel   = new SoftwarePwmChannel(redPin, 400, 1);
            greenChannel = new SoftwarePwmChannel(greenPin, 400, 1);
            blueChannel  = new SoftwarePwmChannel(bluePin, 400, 1);

            redChannel.Start();
            greenChannel.Start();
            blueChannel.Start();
        }
Exemplo n.º 5
0
        void InitMotors()
        {
            Console.WriteLine("Initializing DC Motors... \n");

            gpio.OpenPin(FwL, PinMode.Output);
            gpio.OpenPin(BwL, PinMode.Output);
            gpio.OpenPin(FwR, PinMode.Output);
            gpio.OpenPin(BwR, PinMode.Output);
            gpio.OpenPin(STBY, PinMode.Output);

            LeftChannel.Start();
            RightChannel.Start();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Entry point for example program
        /// </summary>
        /// <param name="args">Command line arguments</param>
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello PWM!");

            using (var pwmChannel = new SoftwarePwmChannel(17, 200, 0))
            {
                pwmChannel.Start();
                for (double fill = 0.0; fill <= 1.0; fill += 0.01)
                {
                    pwmChannel.DutyCycle = fill;
                    Thread.Sleep(500);
                }
            }
        }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
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();
        }
Exemplo n.º 9
0
        public Task LedSoftPWMOn(CancellationToken cancellationToken)
        {
            lock (_locker)
            {
                IsRunning = true;
                return(Task.Run(() =>
                {
                    int brightness = 0;
                    using PwmChannel _pwm = new SoftwarePwmChannel(_softpwmPin, frequency: 400, dutyCycle: 0);
                    _pwm.Start();
                    try
                    {
                        while (IsRunning)
                        {
                            while (brightness != 255)
                            {
                                _pwm.DutyCycle = brightness / 255D;
                                brightness++;
                                Thread.Sleep(10);
                            }

                            while (brightness != 0)
                            {
                                _pwm.DutyCycle = brightness / 255D;
                                brightness--;
                                Thread.Sleep(10);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }));
            }
        }