bluerobotics / navigator-lib

Library to unleash the hardware capabilities, packed with features and fuel for your coding adventures
https://docs.bluerobotics.com/navigator-lib/python/
MIT License
11 stars 5 forks source link

Upgrade: Add pwm array methods, with dynamic lenght #28

Closed RaulTrombin closed 1 year ago

RaulTrombin commented 1 year ago

With this PR, navigator Cpp and Python can set up PWM with dynamic arrays lenghts, as follows.

Cpp:

  init();

  set_pwm_freq_hz(1000);

  PwmChannel channels[4] = {
      PwmChannel::Ch16,
      PwmChannel::Ch2,
      PwmChannel::Ch3,
      PwmChannel::Ch4,
  };

  uint16_t values[4] = {
      500,
      1000,
      1500,
      2000
  };

  set_pwm_channel_value(PwmChannel::All, 0);
  // OR
  set_pwm_channels_value( channels, 1000, 4);
  // OR
  set_pwm_channels_values(channels, values, 4);

  pwm_enable(true);

Python:

    navigator.init()

    navigator.set_pwm_freq_hz(1000)

    navigator.set_pwm_channel_value(PwmChannel.Ch1, 2000)
    # OR
    navigator.set_pwm_channels_value([PwmChannel.Ch1, PwmChannel.Ch16], 1000)
    # OR
    navigator.set_pwm_channels_values([PwmChannel.Ch1, PwmChannel.Ch5], [1000, 500])

    navigator.pwm_enable(True)

Tested on current BlueOS, navigator hardware and osciloscope.

RaulTrombin commented 1 year ago