From 1a48c4d1d8af0e34e19d9d47507b386c37c214ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Runden?= Date: Thu, 11 Jan 2024 22:51:10 +0100 Subject: [PATCH] doit --- quiz/quiz.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/quiz/quiz.py b/quiz/quiz.py index 95faa31..eaa5d52 100644 --- a/quiz/quiz.py +++ b/quiz/quiz.py @@ -2,6 +2,8 @@ import os from flask import Flask, redirect, render_template, request, session import csv # CSV handling import random +import RPi.GPIO as GPIO +import time app = Flask(__name__) @@ -18,8 +20,72 @@ def load_database(): answer = str(row[2]) # Antwort (3. Spalte in der CSV Datenbank) q_a.append({"index": index,"question": question, "answer": answer}) # Eine Liste bauen return q_a - + +### +# 1/4 Drehung = 2 Loch weiter +# sind etwa 14000 Steps +ViertelRundeSteps=14000 + +# ----------------- MOTOR KRAM +GPIO.setmode(GPIO.BCM) +GPIO.setwarnings(False) +coil_A_1_pin = 24 # pink +coil_A_2_pin = 4 # orange +coil_B_1_pin = 23 # blau +coil_B_2_pin = 25 # gelb +coil2_A_1_pin = 18 # pink +coil2_A_2_pin = 22 # orange +coil2_B_1_pin = 17 # blau +coil2_B_2_pin = 27 # gelb + +StepCount = 8 +Seq = list(range(0, StepCount)) +Seq[0] = [0,1,0,0] +Seq[1] = [0,1,0,1] +Seq[2] = [0,0,0,1] +Seq[3] = [1,0,0,1] +Seq[4] = [1,0,0,0] +Seq[5] = [1,0,1,0] +Seq[6] = [0,0,1,0] +Seq[7] = [0,1,1,0] + +GPIO.setup(coil_A_1_pin, GPIO.OUT) +GPIO.setup(coil_A_2_pin, GPIO.OUT) +GPIO.setup(coil_B_1_pin, GPIO.OUT) +GPIO.setup(coil_B_2_pin, GPIO.OUT) +GPIO.setup(coil2_A_1_pin, GPIO.OUT) +GPIO.setup(coil2_A_2_pin, GPIO.OUT) +GPIO.setup(coil2_B_1_pin, GPIO.OUT) +GPIO.setup(coil2_B_2_pin, GPIO.OUT) + +def setStep(w1, w2, w3, w4): + GPIO.output(coil_A_1_pin, w1) + GPIO.output(coil2_A_1_pin, w1) + GPIO.output(coil_A_2_pin, w2) + GPIO.output(coil2_A_2_pin, w2) + GPIO.output(coil_B_1_pin, w3) + GPIO.output(coil2_B_1_pin, w3) + GPIO.output(coil_B_2_pin, w4) + GPIO.output(coil2_B_2_pin, w4) + +def forward(delay, steps): + for i in range(steps): + for j in range(StepCount): + setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) + time.sleep(delay) + +def backwards(delay, steps): + for i in range(steps): + for j in reversed(range(StepCount)): + setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3]) + time.sleep(delay) + +# ----------------- MOTOR KRAM ENDE + def FahreMotor(): + forward(1.0/1000.0, ViertelRundeSteps) + # falls auf der anderen Seite montiert: + #backwards(1.0/1000.0, ViertelRundeSteps) return True fragen_liste = load_database()