本文整理匯總了Python中Arduino.Arduino.analogWrite方法的典型用法代碼示例。如果您正苦於以下問題:Python Arduino.analogWrite方法的具體用法?Python Arduino.analogWrite怎麽用?Python Arduino.analogWrite使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Arduino.Arduino
的用法示例。
在下文中一共展示了Arduino.analogWrite方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: adjustBrightness
# 需要導入模塊: from Arduino import Arduino [as 別名]
# 或者: from Arduino.Arduino import analogWrite [as 別名]
def adjustBrightness(pot_pin, led_pin, baud, port=""):
"""
Adjusts brightness of an LED using a
potentiometer.
"""
board = Arduino(baud, port=port)
while True:
time.sleep(0.01)
val = board.analogRead(pot_pin) / 4
print val
board.analogWrite(led_pin, val)
示例2: softBlink
# 需要導入模塊: from Arduino import Arduino [as 別名]
# 或者: from Arduino.Arduino import analogWrite [as 別名]
def softBlink(led_pin, baud, port=""):
"""
Fades an LED off and on, using
Arduino's analogWrite (PWM) function
"""
board = Arduino(baud, port=port)
i = 0
while True:
i += 1
k = i % 510
if k % 5 == 0:
if k > 255:
k = 510 - k
board.analogWrite(led_pin, k)