internal void SetServoState(bool fIsGateOpen) { _LastGateChange = DateTime.Now; _servoPin.SetActiveDutyCyclePercentage(fIsGateOpen ? .08 : .04); Task.Delay(500).ContinueWith(_ => _servoPin.SetActiveDutyCyclePercentage(0)); this.IsGateOpen = fIsGateOpen; }
public void Backward(double frequency, double dutyCycle) { if (pwmController == null || servoGpioPinEn == null || gpioPinIn1 == null || gpioPinIn2 == null) { return; } var max = pwmController.MaxFrequency; var min = pwmController.MinFrequency; frequency = Math.Min(frequency, max); frequency = Math.Max(frequency, min); var maxDuty = 1.0; var minDuty = 0.0; dutyCycle = Math.Min(dutyCycle, maxDuty); dutyCycle = Math.Max(dutyCycle, minDuty); pwmController.SetDesiredFrequency(frequency); servoGpioPinEn.SetActiveDutyCyclePercentage(dutyCycle); gpioPinIn1.Write(GpioPinValue.High); gpioPinIn2.Write(GpioPinValue.Low); servoGpioPinEn.Start(); }
public void Start() { if (ready) { motorPin.SetActiveDutyCyclePercentage(1); } }
private void Stop() { _pin1.SetActiveDutyCyclePercentage(0); _pin2.SetActiveDutyCyclePercentage(0); _pin3.SetActiveDutyCyclePercentage(0); _pin4.SetActiveDutyCyclePercentage(0); _pin5.Write(GpioPinValue.Low); }
public void TiltUp() { mTopTiltServo.SetActiveDutyCyclePercentage(Math.Max(mBottomPanServo.GetActiveDutyCyclePercentage() - 0.01, 0)); mTopTiltServo.Start(); Task.Run(() => { System.Threading.Tasks.Task.Delay(100).Wait(); mTopTiltServo.Stop(); }); }
private async Task ServoGoTo(double rotationPercent) { var maxPwmPercent = .4; var percentToSet = rotationPercent * maxPwmPercent; _servoPin.SetActiveDutyCyclePercentage(percentToSet); await Task.Delay(500); _servoPin.SetActiveDutyCyclePercentage(0); }
protected override void UpdateDirection(double value) { if (value > 0) { _directionPin1.SetActiveDutyCyclePercentage(1); _directionPin2.SetActiveDutyCyclePercentage(0); } else { _directionPin1.SetActiveDutyCyclePercentage(0); _directionPin2.SetActiveDutyCyclePercentage(1); } }
private async void OnPageLoad(object sender, RoutedEventArgs e) { if (LightningProvider.IsLightningEnabled) { LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider(); } var gpioController = await GpioController.GetDefaultAsync(); if (gpioController == null) { return; } var pwmControllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider()); pwmController = pwmControllers[1]; //hard code from examples to use index 1 pwmController.SetDesiredFrequency(1000); //do *not* debug over this line, it will crash rightDrive = pwmController.OpenPin(13); rightDrive.SetActiveDutyCyclePercentage(0.5); rightDrive.Start(); leftDrive = pwmController.OpenPin(12); leftDrive.SetActiveDutyCyclePercentage(0.5); leftDrive.Start(); }
private void SetCyclePercentage(PwmPin pin, double value) { if (value >= 0 && value <= 1) { pin.SetActiveDutyCyclePercentage(value); } }
// Initialize the PwmController class instance public async void Initialize() { try { var pwmControllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider()); var pwmController = pwmControllers[1]; // the device controller pwmController.SetDesiredFrequency(50); Pwm = pwmController.OpenPin(LED_pin); Pwm.SetActiveDutyCyclePercentage(0); // start at 0% Pwm.Start(); if (Pwm == null) { Debug.WriteLine("ERROR! Pwm device {0} may be in use."); return; } Debug.WriteLine("GPIO pin setup for Pwm."); } catch (Exception e) { Debug.WriteLine("EXEPTION CAUGHT: " + e.Message + "\n" + e.StackTrace); throw; } }
private async void OnLoaded(object sender, RoutedEventArgs routedEventArgs) { if (LightningProvider.IsLightningEnabled) { LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider(); var pwmControllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider()); var pwmController = pwmControllers[1]; // the on-device controller pwmController.SetDesiredFrequency(50); // try to match 50Hz _pin27 = pwmController.OpenPin(27); _pin27.SetActiveDutyCyclePercentage(0); _pin27.Start(); } var gpioController = await GpioController.GetDefaultAsync(); if (gpioController == null) { StatusMessage.Text = "There is no GPIO controller on this device."; return; } _pin22 = gpioController.OpenPin(22); _pin22.SetDriveMode(GpioPinDriveMode.Output); _pin22.Write(GpioPinValue.Low); }
public static void SetMotorDuty(Servo servo, double speedPercentage, Direction direction) { if (speedPercentage < 0 || speedPercentage > 100) { throw new ArgumentOutOfRangeException("speedPercentage", "Must be between 0 and 100 %"); } if (servo == Servo.A) { if (direction == Direction.Back) { DIRA.Write(GpioPinValue.Low); } else { DIRA.Write(GpioPinValue.High); } PWM1.SetDesiredFrequency(5000); PWMA.Start(); PWMA.SetActiveDutyCyclePercentage(speedPercentage / 100); } else { if (direction == Direction.Forvard) { DIRB.Write(GpioPinValue.High); } else { DIRB.Write(GpioPinValue.Low); } PWM3.SetDesiredFrequency(5000); PWMB.Start(); PWMB.SetActiveDutyCyclePercentage(speedPercentage / 100); } }
public static void Main() { Debug.WriteLine("devMobile.Longboard.PwmTest starting"); Debug.WriteLine(PwmController.GetDeviceSelector()); try { PwmController pwm = PwmController.FromId("TIM5"); AdcController adc = AdcController.GetDefault(); AdcChannel adcChannel = adc.OpenChannel(0); PwmPin pwmPin = pwm.OpenPin(PinNumber('A', 0)); pwmPin.Controller.SetDesiredFrequency(1000); pwmPin.Start(); while (true) { double value = adcChannel.ReadRatio(); Debug.WriteLine(value.ToString("F2")); pwmPin.SetActiveDutyCyclePercentage(value); Thread.Sleep(100); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
private void Timer_Tick(ThreadPoolTimer timer) { if (iteration > 18) { timer.Cancel(); motorPin.Stop(); return; } iteration++; if (iteration % 3 == 0) { currentPulseLength = ClockwisePulseLength; secondPulseLength = CounterClockwisePulseLegnth; } else if (iteration % 3 == 1) { currentPulseLength = CounterClockwisePulseLegnth; secondPulseLength = ClockwisePulseLength; } else { currentPulseLength = 0; secondPulseLength = 0; } double desiredPercentage = currentPulseLength / (1000.0 / pwmController.ActualFrequency); motorPin.SetActiveDutyCyclePercentage(desiredPercentage); }
private void Timer_Tick(ThreadPoolTimer timer) { if (iteration > 4) { timer.Cancel(); motorPin.Stop(); motorPin.Dispose(); return; } iteration++; System.Diagnostics.Debug.WriteLine(iteration); if (iteration == 1 || iteration == 3) { currentPulseLength = ClockwisePulseLength; secondPulseLength = CounterClockwisePulseLength; } if (iteration == 2 || iteration == 4) { currentPulseLength = CounterClockwisePulseLength; secondPulseLength = ClockwisePulseLength; } double desiredPercentage = currentPulseLength / (1000.0 / pwmController.ActualFrequency); motorPin.SetActiveDutyCyclePercentage(desiredPercentage); }
public async Task <bool> Rotate(LuisResult result, object context, object speak) { var speech = (App.SpeechFunc)speak; var c = (Context)context; if (c.IsIoTCore) { speech("Feel the burn baby!"); pwmController = (await PwmController.GetControllersAsync(PwmSoftware.PwmProviderSoftware.GetPwmProvider()))[0]; pwmController.SetDesiredFrequency(50); try { motorPin = pwmController.OpenPin(26); } catch { } motorPin.SetActiveDutyCyclePercentage(RestingPulseLegnth); motorPin.Start(); iteration = 0; timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromSeconds(1)); } else { speech("I am a fully functioning PC, not a robot."); } return(true); }
public void ChangeSpeed(double SpeedMotorA, double SpeedMotorB) { SpeedValueA = SpeedMotorA; SpeedValueB = SpeedMotorB; SpeedA.SetActiveDutyCyclePercentage(SpeedValueA); SpeedB.SetActiveDutyCyclePercentage(SpeedValueB); }
public async void StepperMotorExample() { MotorHat2348 mh = null; PwmStepperMotor stepper = null; PwmPin pwm = null; if (mh == null) { // Create a driver object for the HAT at address 0x60 mh = new MotorHat2348(0x60); // Create a stepper motor object at the specified ports and steps per rev stepper = mh.CreateStepperMotor(1, 2, 200); // Create a PwmPin object at one of the auxiliary PWMs on the HAT pwm = mh.CreatePwm(1); } // step 200 full steps in the forward direction using half stepping (so 400 steps total) at 30 rpm stepper.SetSpeed(30); await stepper.StepAsync(200, Direction.Forward, SteppingStyle.Half); // Activate the pin and set it to 50% duty cycle pwm.Start(); pwm.SetActiveDutyCyclePercentage(0.5); // for demonstration purposes we will wait 10 seconds to observe the PWM and motor operation. await Task.Delay(10000); // Stop the auxiliary PWM pin pwm.Stop(); // Dispose of the MotorHat and free all its resources mh.Dispose(); }
/// <summary> /// /// </summary> /// <returns></returns> private async Task InitBuzzer() { pwmController = (await PwmController.GetControllersAsync(PwmSoftware.PwmProviderSoftware.GetPwmProvider()))[0]; pwmController.SetDesiredFrequency(40); buzzer = pwmController.OpenPin(BUZZER_PIN); buzzer.SetActiveDutyCyclePercentage(RestingPulseLegnth); }
private async void OnLoaded(object sender, RoutedEventArgs routedEventArgs) { if (LightningProvider.IsLightningEnabled) { LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider(); var pwmControllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider()); var pwmController = pwmControllers[1]; // the on-device controller pwmController.SetDesiredFrequency(50); // try to match 50Hz internetLed = new InternetLed(); _pin18 = pwmController.OpenPin(18); while (true) { await internetLed.GetThrottleFromWeb(); double test = internetLed.getThrottle() / 100.0; _pin18.SetActiveDutyCyclePercentage(internetLed.getThrottle() / 100.0); _pin18.Start(); await Task.Delay(200); } } }
/// <summary> /// Initialize the Pins with default values of low and 0 /// </summary> /// <param name="GPIO_pin">The number of the GPIO pin to open</param> /// <param name="PWM_pin">The number of the PWM pin to open</param> /// <param name="gpioController">The gpio controller</param> /// <param name="pwmController">The PWM controller</param> public void Init(int GPIO_pin, int PWM_pin, GpioController gpioController, PwmController pwmController) { _pwmPin = pwmController.OpenPin(PWM_pin); _GPIOPin = gpioController.OpenPin(GPIO_pin); _GPIOPin.Write(GpioPinValue.Low); _GPIOPin.SetDriveMode(GpioPinDriveMode.Output); _pwmPin.SetActiveDutyCyclePercentage(0); }
private async void InitPwm() { //_controller = (await PwmController.GetControllersAsync(PwmPCA9685.PwmProviderSoftware.GetPwmProvider())).First(); _controller = (await PwmController.GetControllersAsync(PwmSoftware.PwmProviderSoftware.GetPwmProvider())).First(); _controller.SetDesiredFrequency(40); _pin = _controller.OpenPin(5); _pin.SetActiveDutyCyclePercentage(0.5); }
/// <summary>Stops playback.</summary> public void Stop() { if (IsPlaying) { lock (_syncRoot) _playlist.Clear(); _worker.Join(250); if (_worker != null && _worker.IsAlive) { _worker.Abort(); } } _pwmPin.Controller.SetDesiredFrequency(100.0); _pwmPin.SetActiveDutyCyclePercentage(0.0001); _pwmPin.Stop(); }
private void DutyCycleSlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e) { if (_pwmController != null) { var slider = (Slider)sender; var value = slider.Value; _outputPin.SetActiveDutyCyclePercentage(value); } }
/// <summary> /// Set Red Pin Duty Cycle Percentage /// </summary> /// <param name="percentage">Percentage(From 0 to 1)</param> public void SetRedPin(double percentage) { if (type == RgbType.CommonCathode) { redPin.SetActiveDutyCyclePercentage(percentage); } else { redPin.SetActiveDutyCyclePercentage(1.0 - percentage); } }
public void SetValuesFromRgb(int red, int green, int blue) { var redCycle = red / 255.000f * 100.000f; var greenCycle = green / 255.000f * 100.000f; var blueCycle = blue / 255.000f * 100.000f; _redPin.SetActiveDutyCyclePercentage(redCycle); _greenPin.SetActiveDutyCyclePercentage(greenCycle); _bluePin.SetActiveDutyCyclePercentage(blueCycle); }
/// <summary> /// Creates an instance. /// </summary> /// <param name="pin">The PWM-enabled pin to use.</param> public AnalogPwmOutput(DigitalPwmOutputPin pin) { if (_controller == null) { CreateController(PwmFrequency); } _pin = _controller.OpenPin((int)pin); _pin.SetActiveDutyCyclePercentage(0.0); _pin.Start(); }
private void SetColor(int color) { double rVal = color >> 8; double gVal = color & 0x00FF; rVal = Map(rVal, 0, 255, 0, 1); gVal = Map(gVal, 0, 255, 0, 1); pinR.SetActiveDutyCyclePercentage(rVal); pinG.SetActiveDutyCyclePercentage(gVal); }
async void OnLoaded(Object sender, Windows.UI.Xaml.RoutedEventArgs e) { if (Microsoft.IoT.Lightning.Providers.LightningProvider.IsLightningEnabled) { LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider(); } else { return; } var controllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider()); if (controllers == null) { return; } var controller = controllers[1]; controller.SetDesiredFrequency(50.0); _pwmPin = controller.OpenPin(LED_PIN); _pwmPin.SetActiveDutyCyclePercentage(1.0); _pwmPin.Start(); while (true) { for (var i = INCREMENT; i > 0; i--) { var brightness = i / INCREMENT; _pwmPin.SetActiveDutyCyclePercentage(brightness); Task.Delay(DELAY).Wait(); } for (var i = 0; i < INCREMENT; i++) { var brightness = i / INCREMENT; _pwmPin.SetActiveDutyCyclePercentage(brightness); Task.Delay(DELAY).Wait(); } } }
private async void Timer_Tick(object sender, object e) { if (IsClockwise) { for (int i = 0; i < 98; i++) { pwmPin.SetActiveDutyCyclePercentage(i / 100.0); await Task.Delay(100); } IsClockwise = false; } else { for (int i = 98; i > 0; i--) { pwmPin.SetActiveDutyCyclePercentage(i / 100.0); await Task.Delay(100); } IsClockwise = true; } }