Physical computing/Digitale output: verschil tussen versies
Naar navigatie springen
Naar zoeken springen
Regel 9: | Regel 9: | ||
<code>pin.write_digital(value)</code>: Set the pin to high if value is 1, or to low, if it is 0. | <code>pin.write_digital(value)</code>: Set the pin to high if value is 1, or to low, if it is 0. | ||
<syntaxhighlight lang=python> | |||
from microbit import pin0, pin1 | |||
pin0.write_digital(0) | |||
pin0.write_digital(1) | |||
# default for read_digital: PULL_DOWN | |||
print(pin1.read_digital()) # get value, 0 or 1 | |||
pin2.set_pull(PULL_UP) | |||
print(pint2.read_digital()) # get value, 0 or 1 | |||
</syntaxhighlight> | |||
== microPython == | == microPython == |
Versie van 10 nov 2019 09:27
microbit
- https://microbit-micropython.readthedocs.io/en/v1.0.1/pin.html
- library:
microbit
- function(s):
pin.write_digital(value)
Met de functie pin.write_digital(value)
stel je de waarde van een output-pin in.
Je hoeft deze pin niet van te voren in te stellen als output-pin.
pin.write_digital(value)
: Set the pin to high if value is 1, or to low, if it is 0.
from microbit import pin0, pin1
pin0.write_digital(0)
pin0.write_digital(1)
# default for read_digital: PULL_DOWN
print(pin1.read_digital()) # get value, 0 or 1
pin2.set_pull(PULL_UP)
print(pint2.read_digital()) # get value, 0 or 1
microPython
- library:
machine
- class:
Pin
- function(s):
In microPython moet je eerst de pin instellen als output-pin of als input-pin. In het laatste geval kun je ook instellen of je de interne pull-up weerstand (of pull-down?) gebruikt.
from machine import Pin
p0 = Pin(0, Pin.OUT) # create output pin on GPIO0
p0.on() # set pin to "on" (high) level
p0.off() # set pin to "off" (low) level
p0.value(1) # set pin to on/high
p2 = Pin(2, Pin.IN) # create input pin on GPIO2
print(p2.value()) # get value, 0 or 1
p4 = Pin(4, Pin.IN, Pin.PULL_UP) # enable internal pull-up resistor
p5 = Pin(5, Pin.OUT, value=1) # set pin high on creation