【问题标题】:Arduino with servos, tone() funcition and RGB led带有舵机、tone() 功能和 RGB LED 的 Arduino
【发布时间】:2020-11-19 18:52:10
【问题描述】:

我正在做一个带有 2 个伺服器、1 个蜂鸣器和 1 个 RGB LED 的 Arduino 项目...

我使用的是 Arduino Uno 板,带有 6 个 PWM 引脚(3、5、6、9、10、11)...

问题是,我需要 3 个带有 PWM 到 RGB LED 的引脚。但伺服库禁用引脚 9 和 10 上的 PWM。来自https://www.arduino.cc/reference/en/libraries/servo/On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins.

和tone()函数使用蜂鸣器干扰引脚3和11上的PWM输出。来自https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/Use of the tone() function will interfere with PWM output on pins 3 and 11 (on boards other than the Mega).

所以,我的 RGB LED 只有针脚 5 和 6...

有没有办法在没有库的情况下使用 Servo?或者不用tone()函数来控制蜂鸣器?

【问题讨论】:

  • 使用有源蜂鸣器。这将通过简单的 digitalWrite 嗡嗡作响
  • 主动蜂鸣器是一种方式。另一个是意识到您不需要蹩脚和臃肿的库来控制步进器。您只需要每个步进器一个引脚。我多年前的六足机器人在一个 16 位定时器上使用了 18 个伺服系统。

标签: arduino arduino-uno led pwm servo


【解决方案1】:

Juraj 所说的。另外:

您可以使用一些软件 PWM 库,请参阅 SoftPWM 和(第一个的编辑分支)SoftPWM

它们只使用一个定时器,并且可以在任何引脚上产生 PWM 信号。

我自己没有尝试和测试过这些库,但我认为它们运行良好。

如果您曾经采用 SAMD21 方式,那么对于那些使用该微控制器 here 的 Arduino 来说,有一个 PWM 库。不得不说,因为是我写的。对不起。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-03
    相关资源
    最近更新 更多