public static void Main() { bool goingUp = true; float dutyCycle = .00f; // there is no PWM output pin connected to an LED in STM32F769I_DISCO // the closest one is LD3 connected to PA12 and exposed in Arduino connector, pad D13 // to see the PWM output in this LED need to short these two pins // set this GPIO pin as input so it doesn't mess up with PWM output GpioPin dummyPad = GpioController.GetDefault().OpenPin(PinNumber('A', 12)); dummyPad.SetDriveMode(GpioPinDriveMode.Input); PwmController pwmController; PwmPin pwmPin; // we'll be using PA11, exposed in Arduino connector, pad D10 // as the PWM output pin, this one is TIM11_CH4 pwmController = PwmController.FromId("TIM1"); pwmController.SetDesiredFrequency(5000); // open the PWM pin pwmPin = pwmController.OpenPin(PinNumber('A', 11)); // set the duty cycle pwmPin.SetActiveDutyCyclePercentage(dutyCycle); // start the party pwmPin.Start(); for (;;) { if (goingUp) { // slowly increase light intensity dutyCycle += 0.05f; // change direction if reaching maximum duty cycle (100%) if (dutyCycle > .95) { goingUp = !goingUp; } } else { // slowly decrease light intensity dutyCycle -= 0.05f; // change direction if reaching minimum duty cycle (0%) if (dutyCycle < 0.10) { goingUp = !goingUp; } } // update duty cycle pwmPin.SetActiveDutyCyclePercentage(dutyCycle); Thread.Sleep(50); } }
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); } }
public ServoMotor(string controller, int PwmPinNumber) { PwmController PWM = PwmController.FromId(controller); servo = PWM.OpenPin(PwmPinNumber); PWM.SetDesiredFrequency(1 / 0.020); }
/// <summary> /// Constructor of Grove ServoMotor module /// </summary> /// <param name="controller">Id of pwm controller</param> /// <param name="pwmPinNumber">Pwm pin number of board</param> public ServoMotor(string controller, int pwmPinNumber) { PwmController pwm = PwmController.FromId(controller); _servo = pwm.OpenPin(pwmPinNumber); pwm.SetDesiredFrequency(1 / 0.020); }
/// <summary>Constructs a new instance.</summary> /// <param name="socketNumber">The socket that this module is plugged in to.</param> public MotorDriverL298(string PwmId1, string PwmId2, int PwmPinCtl1, int PwmPinCtl2, int DigitalPin6, int DigitalPin9) { //Socket socket = Socket.GetSocket(socketNumber, true, this, null); //socket.EnsureTypeIsSupported('P', this); var pwmcontroller1 = PwmController.FromId(PwmId1); var pwmcontroller2 = PwmController.FromId(PwmId2); this.pwms = new PwmPin[2] { pwmcontroller1.OpenPin(PwmPinCtl1), pwmcontroller2.OpenPin(PwmPinCtl2) //PwmPinFactory.Create(socket, Socket.Pin.Eight, false, this), //PwmPinFactory.Create(socket, Socket.Pin.Seven, false, this) }; var controller = GpioController.GetDefault(); this.directions = new GpioPin[2] { controller.OpenPin(DigitalPin6), controller.OpenPin(DigitalPin9) // GpioPinFactory.Create(socket, Socket.Pin.Six, false, this), // GpioPinFactory.Create(socket, Socket.Pin.Nine, false, this) }; this.directions[0].SetDriveMode(GpioPinDriveMode.Output); this.directions[1].SetDriveMode(GpioPinDriveMode.Output); this.lastSpeeds = new double[2] { 0, 0 }; this.Frequency = 25000; this.StopAll(); }
/// <summary>Creates a pwm output on the given pin.</summary> /// <param name="PwmId">The ID PWM to create the interface on.</param> /// <param name="PWMPin">The pwm pin number.</param> /// <returns>The new interface.</returns> public PwmPin CreatePwmOutput(string PwmId, int PWMPin) { //socket.EnsureTypeIsSupported('P', this); var PwmController1 = PwmController.FromId(PwmId); var pwm = PwmController1.OpenPin(PWMPin); return(pwm); }
/// <summary> /// Constructor of Tunes /// </summary> /// <param name="controller">string of controller (must be a P Socket)</param> /// <param name="pin">Pin number (generally pin 9 of P Socket)</param> public Tunes(string controller, int pin) { PwmController ctl = PwmController.FromId(controller); _pwmPin = ctl.OpenPin(pin); _playlist = new Queue(); _syncRoot = new object(); }
/// <summary>Constructs a new instance.</summary> /// <param name="socketNumber">The socket that this module is plugged in to.</param> public Tunes(string Ctl2PwmId, int Ctl2PinPC20) { //Socket socket = Socket.GetSocket(socketNumber, true, this, null); //socket.EnsureTypeIsSupported('P', this); var controller = PwmController.FromId(Ctl2PwmId);// (PwmId); this.pwm = controller.OpenPin(Ctl2PinPC20);//GTI.PwmOutputFactory.Create(socket, Socket.Pin.Nine, false, this); this.playlist = new Queue(); this.syncRoot = new object(); }
public ServoMotor(string pwmId, ServoType type, int pwmPin) { PwmController pwmController = PwmController.FromId(pwmId); pwmController.SetDesiredFrequency(50); this.ConfigurePulseParameters(1.0, 2.0); this.servo = pwmController.OpenPin(pwmPin); this.type = type; this.Position = 0; }
public LightBulb() { PwmController pwmController = PwmController.FromId("TIM3"); pwmController.SetDesiredFrequency(10000); this.red = pwmController.OpenPin(BrainPad2.Light.Red); this.green = pwmController.OpenPin(BrainPad2.Light.Greeen); this.blue = pwmController.OpenPin(BrainPad2.Light.Blue); this.red.Start(); this.green.Start(); this.blue.Start(); this.TurnColor(0, 0, 0); }
static ZumoBot() { led = GpioController.GetDefault().OpenPin(FEZ.GpioPin.D13); led.SetDriveMode(GpioPinDriveMode.Output); button = GpioController.GetDefault().OpenPin(FEZ.GpioPin.D12); button.SetDriveMode(GpioPinDriveMode.InputPullUp); PwmController pwm = PwmController.FromId(FEZ.PwmPin.Controller3.Id); pwm.SetDesiredFrequency(4 * 1000); Buzzer = pwm.OpenPin(FEZ.PwmPin.Controller3.D6); // D3 or D6 Buzzer.Stop(); Buzzer.SetActiveDutyCyclePercentage(0.5); voltage = AdcController.GetDefault().OpenChannel(FEZ.AdcChannel.A1); }
public static void Main() { Debug.WriteLine("devMobile.Longboard starting"); Debug.WriteLine($"I2C:{I2cDevice.GetDeviceSelector()}"); Debug.WriteLine($"PWM:{PwmController.GetDeviceSelector()}"); try { Debug.WriteLine("LED Starting"); GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 10)); led.SetDriveMode(GpioPinDriveMode.Output); led.Write(GpioPinValue.Low); Debug.WriteLine("LED Starting"); WiiNunchuk nunchuk = new WiiNunchuk("I2C1"); Debug.WriteLine("ESC Starting"); PwmController pwm = PwmController.FromId("TIM5"); PwmPin pwmPin = pwm.OpenPin(PinNumber('A', 1)); pwmPin.Controller.SetDesiredFrequency(PulseFrequency); pwmPin.Start(); Debug.WriteLine("Thread.Sleep Starting"); Thread.Sleep(2000); Debug.WriteLine("Mainloop Starting"); while (true) { nunchuk.Read(); double duration = Map(nunchuk.AnalogStickY, WiiNunchukYMinimum, WiiNunchukYMaximum, PulseDurationMinimum, PulseDurationMaximum); Debug.WriteLine($"Value:{nunchuk.AnalogStickY} Duration:{duration:F3}"); pwmPin.SetActiveDutyCyclePercentage(duration); led.Toggle(); Thread.Sleep(ThrottleUpdatePeriod); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
/// <summary> /// Constructor of MotorDriverL298 /// </summary> /// <param name="pinDir1">pin of direction for Motor 1, pin 6 of P Socket</param> /// <param name="pinDir2">pin of direction for Motor 2, pin 7 of P Socket</param> /// <param name="pinPwm1">pin of Pwm for Motor 1, pin 8 of P Socket</param> /// <param name="pinPwm2">pin of Pwm for Motor 2, pin 9 of P Socket</param> /// <param name="idPwmController1">id of Pwm for Motor 1</param> /// <param name="idPwmController2">id of Pwm for Motor 2</param> public MotorDriverL298(int pinDir1, int pinDir2, int pinPwm1, int pinPwm2, string idPwmController1, string idPwmController2) { _lastSpeeds = new double[] { 0, 0 }; Frequency = 25000; _controllers = new[] { PwmController.FromId(idPwmController1), PwmController.FromId(idPwmController2), }; foreach (var controller in _controllers) { controller.SetDesiredFrequency(Frequency); } _pwms = new[] { _controllers[0].OpenPin(pinPwm1), _controllers[1].OpenPin(pinPwm2), }; foreach (var pwmPin in _pwms) { pwmPin.Start(); } _directions = new[] { GpioController.GetDefault().OpenPin(pinDir1, GpioSharingMode.Exclusive), GpioController.GetDefault().OpenPin(pinDir2, GpioSharingMode.Exclusive), }; foreach (var dir in _directions) { dir.SetDriveMode(GpioPinDriveMode.Output); dir.Write(GpioPinValue.Low); } StopAll(); }
SparkfunArdumoto(int PinD2, int PinD4, int PinD3, int PinD11, string PWM1Id, string PWM3Id) { var GPIO = GpioController.GetDefault(); MotorA.SetDriveMode(GpioPinDriveMode.Output); MotorB.SetDriveMode(GpioPinDriveMode.Output); MotorA = GPIO.OpenPin(PinD2); MotorB = GPIO.OpenPin(PinD4); var PWM1 = PwmController.FromId(PWM1Id); var PWM3 = PwmController.FromId(PWM3Id); SpeedA = PWM1.OpenPin(PinD3); SpeedB = PWM3.OpenPin(PinD11); PWM1.SetDesiredFrequency(5000); PWM3.SetDesiredFrequency(5000); SpeedA.Start(); SpeedB.Start(); ChangeSpeed(0.0, 0.0); ChangeDirection(MoveDirection.Forward); }
/// <summary> /// Initializes the PwmController instance used by every instance of this class. /// </summary> /// <param name="pwmFrequency"></param> private static void CreateController(double pwmFrequency) { _controller = PwmController.FromId("TIM1"); _controller.SetDesiredFrequency(pwmFrequency); }
public Buzzer() { this.controller = PwmController.FromId("TIM4"); this.buzz = controller.OpenPin(24); }