static void LedInit(PwmController controller) { Red = controller.OpenPin(LedPinRed); Green = controller.OpenPin(LedPinGreen); Blue = controller.OpenPin(LedPinBlue); Red.Start(); Green.Start(); Blue.Start(); }
public async void Run(IBackgroundTaskInstance taskInstance) { deferral = taskInstance.GetDeferral(); // pwmController = (await PwmController.GetControllersAsync(PwmPCA9685.PwmProviderPCA9685.GetPwmProvider()))[0]; pwmController = (await PwmController.GetControllersAsync(PwmSoftware.PwmProviderSoftware.GetPwmProvider()))[0]; pwmController.SetDesiredFrequency(50); motorPin = pwmController.OpenPin(13); motorPin.SetActiveDutyCyclePercentage(RestingPulseLegnth); motorPin.Start(); secondMotorPin = pwmController.OpenPin(6); secondMotorPin.SetActiveDutyCyclePercentage(RestingPulseLegnth); secondMotorPin.Start(); timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromSeconds(2)); }
public Windows10PwmDriverChannel(WinPwm.PwmController winController, int channelIndex) { _winPin = winController.OpenPin(channelIndex); if (_winPin == null) { throw new ArgumentOutOfRangeException($"The PWM chip is unable to open a channel at index {channelIndex}.", nameof(channelIndex)); } }
/// <summary> /// Initializes a new instance of the <see cref="Windows10PwmChannel"/> class. /// </summary> /// <param name="chip">The PWM chip number.</param> /// <param name="channel">The PWM channel number.</param> /// <param name="frequency">The frequency in hertz.</param> /// <param name="dutyCyclePercentage">The duty cycle percentage represented as a value between 0.0 and 1.0.</param> public Windows10PwmChannel( int chip, int channel, int frequency = 400, double dutyCyclePercentage = 0.5) { // When running on Hummingboard we require to use the default chip. var deviceInfo = new EasClientDeviceInformation(); bool useDefaultChip = false; if (deviceInfo.SystemProductName.IndexOf("Hummingboard", StringComparison.OrdinalIgnoreCase) >= 0) { useDefaultChip = true; } // Open the Windows PWM controller for the specified PWM chip. string deviceSelector = useDefaultChip ? WinPwm.PwmController.GetDeviceSelector() : WinPwm.PwmController.GetDeviceSelector($"PWM{chip}"); DeviceInformationCollection deviceInformationCollection = DeviceInformation.FindAllAsync(deviceSelector).WaitForCompletion(); if (deviceInformationCollection.Count == 0) { throw new ArgumentException($"No PWM device exists for PWM chip at index {chip}.", nameof(chip)); } string deviceId = deviceInformationCollection[0].Id; _winController = WinPwm.PwmController.FromIdAsync(deviceId).WaitForCompletion(); _winPin = _winController.OpenPin(channel); if (_winPin == null) { throw new ArgumentOutOfRangeException($"The PWM chip is unable to open a channel at index {channel}.", nameof(channel)); } Frequency = frequency; DutyCyclePercentage = dutyCyclePercentage; }