【发布时间】: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