Benutzer-Werkzeuge

Webseiten-Werkzeuge


projekt:python_erste_skripte

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
projekt:python_erste_skripte [2026/02/08 18:20] – [Ergebnis] torsten.roehlprojekt:python_erste_skripte [2026/02/08 18:45] (aktuell) torsten.roehl
Zeile 35: Zeile 35:
 Wechsle anschließend in die Umgebung, um die Examples zu bearbeiten! Wechsle anschließend in die Umgebung, um die Examples zu bearbeiten!
  
-===== Example 1: todo =====+===== Example 1: "Schnell, schneller, am schnellsten"  =====
  
-===== Example 2: todo =====+<code python> 
 +#!/usr/bin/env python3
  
 +# Testet die Reaktionszeit
 +# @author: Max Mustermann
 +# @version: 1.0
 +# @usage:    ./reaction.py
  
  
 +import time
 +import random
  
-====== Raspberry-Pi-KursprojektGPIO-App mit wachsender Architektur ======+def main(): 
 +    print("Reaktionstest"
 +    print("Drücke ENTER, sobald >>> JETZT <<< erscheint."
 +    print("Bereit..."
 +    input()
  
-  * erst reines Python +    wartezeit = random.uniform(2, 6) 
-  * dann Dauerprozess +    time.sleep(wartezeit)
-  * dann Web-API +
-  * dann Apache davor +
-  * EIN Projekt, keine Neuentwicklung+
  
-**ENV:** gpio_projects   +    print("JETZT!")
-**Projektpfad:** ~/devel/gpio_projects   +
- +
- +
- +
-==== 3) Projektstruktur Phase 1 ==== +
- +
-<code> +
-gpio_projects/ +
- ├── gpio_hw.py +
- ├── logic.py +
- ├── main.py +
- └── gpio_projects/        # ENV +
- +
-(gpio_envpi@raspi88:~/devel/gpio_projects $ tree -L 1    +
-+
-├── gpio_env +
-├── gpio_hw.py +
-├── logic.py +
-└── main.py+
  
 +    start = time.time()
 +    input()
 +    ende = time.time()
  
 +    reaktion = ende - start
 +    print(f"Deine Reaktionszeit: {reaktion:.3f} Sekunden")
  
 +if __name__ == "__main__":
 +    main()
 </code> </code>
  
----- 
  
-==== 4) gpio_hw.py ==== +===== Example 2todo =====
- +
-<code python  gpio_hw.py> +
-import RPi.GPIO as GPIO +
- +
-PIN = 17 +
- +
-GPIO.setmode(GPIO.BCM) +
-GPIO.setup(PIN, GPIO.OUT) +
- +
-def on(): +
-    GPIO.output(PIN, GPIO.HIGH) +
- +
-def off(): +
-    GPIO.output(PIN, GPIO.LOW) +
- +
-def status(): +
-    return GPIO.input(PIN) +
- +
-def cleanup(): +
-    GPIO.cleanup() +
-</code> +
- +
----- +
- +
-==== 5) logic.py ==== +
- +
-<code python logic.py> +
-import gpio_hw +
- +
-def turn_on(): +
-    gpio_hw.on() +
-    return "on" +
- +
-def turn_off(): +
-    gpio_hw.off() +
-    return "off" +
- +
-def get_status(): +
-    return "on" if gpio_hw.status() else "off" +
-</code> +
- +
----- +
- +
-==== 6) main.py ==== +
- +
-<code python  main.py> +
-import logic +
-import gpio_hw +
- +
-print("GPIO CLI gestartet (CTRL+C beendet)"+
- +
-try: +
-    while True: +
-        cmd = input("on / off / status > ").strip() +
-        if cmd == "on": +
-            print(logic.turn_on()) +
-        elif cmd == "off": +
-            print(logic.turn_off()) +
-        elif cmd == "status": +
-            print(logic.get_status()) +
-except KeyboardInterrupt: +
-    pass +
-finally: +
-    gpio_hw.cleanup() +
-</code> +
- +
----- +
- +
-==== 7) Start Phase 1 ==== +
- +
-<code bash> +
-cd ~/devel/gpio_projects +
-source gpio_projects/bin/activate +
-python3 main.py +
-</code> +
- +
----- +
- +
-===== PHASE 3 – Web später ===== +
- +
-<code bash> +
-pip install fastapi uvicorn +
-</code> +
- +
----- +
- +
-===== systemd später mit dieser ENV ===== +
- +
-<code> +
-ExecStart=/home/pi/devel/gpio_projects/gpio_projects/bin/uvicorn api:app --host 127.0.0.1 --port 8000 +
-</code> +
- +
-----+
  
  
projekt/python_erste_skripte.1770574830.txt.gz · Zuletzt geändert: von torsten.roehl