Das Objekt Pin: Difference between revisions

From Attraktor Wiki
Jump to navigation Jump to search
Created page with "In Python ist alles ein Objekt und Objekte haben eine ID. <pre> >>> from machine import Pin >>> print(Pin(11)) Pin(GPIO11, mode=IN, pull=PULL_DOWN) >>> b_up = Pin(11, Pin..."
 
No edit summary
Line 1: Line 1:
In Python ist alles ein Objekt und Objekte haben eine ID.
In Python ist alles ein Objekt und Objekte haben eine ID.
<br>


Die Instanz Pin(11) existiert, auch wenn GPIO11 noch nicht initialisiert worden ist:
<pre>
<pre>
>>> from machine import Pin
>>> from machine import Pin
>>> id(Pin(11))
    268904804
</pre>
Sie besitzt auch schon einige default Einstellungen:
<pre>
>>> print(Pin(11))
>>> print(Pin(11))
     Pin(GPIO11, mode=IN, pull=PULL_DOWN)
     Pin(GPIO11, mode=IN, pull=PULL_DOWN)
</pre>
Wenn eine Instanz von Pin erzeugt wird, so wird ihr ein Namen zugewiesen und ggf. die Einstellungen gesetzt:
<pre>
>>> b_up = Pin(11, Pin.IN, Pin.PULL_DOWN)
>>> b_up = Pin(11, Pin.IN, Pin.PULL_DOWN)
>>> Pin(11)
>>> id(b_up)
     Pin(GPIO11, mode=IN, pull=PULL_DOWN)
     268904804
>>> print(Pin(11))
    Pin(GPIO11, mode=IN, pull=PULL_DOWN)
>>> print(b_up)
>>> print(b_up)
     Pin(GPIO11, mode=IN, pull=PULL_DOWN)
     Pin(GPIO11, mode=IN, pull=PULL_DOWN)
</pre>
Eine solche Instanz kann auch mehrere Namen haben:
<pre>
>>> x = b_up
>>> x = b_up
>>> print(x)
>>> print(x)
     Pin(GPIO11, mode=IN, pull=PULL_DOWN)
     Pin(GPIO11, mode=IN, pull=PULL_DOWN)
>>> id(x)
    268904804
</pre>
</pre>
Es bleibt aber immer die selbe ID, also auch das selbe Objekt.
<br>

Revision as of 22:38, 18 January 2024

In Python ist alles ein Objekt und Objekte haben eine ID.

Die Instanz Pin(11) existiert, auch wenn GPIO11 noch nicht initialisiert worden ist:

>>> from machine import Pin
>>> id(Pin(11))
    268904804

Sie besitzt auch schon einige default Einstellungen:

>>> print(Pin(11))
    Pin(GPIO11, mode=IN, pull=PULL_DOWN)

Wenn eine Instanz von Pin erzeugt wird, so wird ihr ein Namen zugewiesen und ggf. die Einstellungen gesetzt:

>>> b_up = Pin(11, Pin.IN, Pin.PULL_DOWN)
>>> id(b_up)
    268904804
>>> print(b_up)
    Pin(GPIO11, mode=IN, pull=PULL_DOWN)

Eine solche Instanz kann auch mehrere Namen haben:

>>> x = b_up
>>> print(x)
    Pin(GPIO11, mode=IN, pull=PULL_DOWN)
>>> id(x)
    268904804

Es bleibt aber immer die selbe ID, also auch das selbe Objekt.