feat: Add section "Signal" as subsection of "LED ansteuern"

This commit is contained in:
Laborratte5 2024-05-08 17:25:57 +02:00
parent cdd4d7ff4a
commit 8e78b55389
Signed by: Laborratte5
GPG key ID: 3A30072E35202C02

View file

@ -316,6 +316,107 @@
}, },
"outputs": [], "outputs": [],
"source": [] "source": []
},
{
"cell_type": "markdown",
"id": "fad56042-ee95-4b77-ac19-5c82d6966c8a",
"metadata": {
"editable": false,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"### Signal\n",
"\n",
"Da sich das vertauschte `on()` und `off()` nicht gut anfühlt und bei größeren Programmen auch schnell zu Fehler führen kann, haben die Entwickler von MicroPython hierfür abhilfe geschaffen.\n",
"Mithilfe von `machine.Signal` kann man `on()` und `off()` für einen bestehenden Pin *invertieren*, das heißt vertauschen lassen.\n",
"Somit muss man nur bei der Initialisierung des Signal daran denken, dass `on()` und `off()` vertauscht sind.\n",
"Danach kann man das Signal wie einen normalen Pin benutzen und das invertieren wird automatisch vorgenommen."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c821d21a-88f1-43e7-8d5e-2cfab63dba6a",
"metadata": {
"editable": false,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"led_signal = machine.Signal(led_pin, invert=True)"
]
},
{
"cell_type": "markdown",
"id": "941d1e50-6067-41f8-b216-8b61771febce",
"metadata": {
"editable": false,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"Testet im folgenden ein bisschen mit dem Signal"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5feeda4a-682f-419e-bda4-b8c85c7e9d5e",
"metadata": {
"editable": false,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"led_signal.off()"
]
},
{
"cell_type": "markdown",
"id": "561aebd6-cd18-4ad1-b39d-cfdf5db5a035",
"metadata": {
"editable": false,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"Versucht den Code zum anschalten des Signals selbst herauszufinden. (Tipp: `Signal` funktioniert ähnlich wie `Pin`)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "69014430-eb93-4f42-b12d-d4a3c3135043",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "6ba975a5-1a7a-44e9-be8f-3483ec595ec0",
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {