NodeMCU Projects: Difference between revisions

Content added Content deleted
Line 112: Line 112:
*Control a hobby servo
*Control a hobby servo
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
servo = machine.PWM(machine.Pin(12), freq=50)
servo = machine.PWM(machine.Pin(12), freq=50)
servo.duty(40)
servo.duty(40)
servo.duty(115)
servo.duty(115)
servo.duty(77)
servo.duty(77)
</syntaxhighlight>
</syntaxhighlight>


<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
servo = machine.PWM(machine.Pin(12), freq=50)
servo = machine.PWM(machine.Pin(12), freq=50)
while True:
while True:
servo.duty(urandom.getrandbits(8))
servo.duty(urandom.getrandbits(8))
time.sleep(1)
time.sleep(1)
</syntaxhighlight>
</syntaxhighlight>