Hallo,
ich habe folgendes Problem. Ich habe ein Programm um die Entfernung zu Messen.
Nun ich habe ich ein weiter Programm geschrieben für ein GUI. Daher meine Frage wie bekomme ich den Wert aus der Messung in das neue Programm.
Habe es mit import from probiert, doch dann würde das Programm der Messung gestartet und das GUI öffnete sich nicht mehr.
Habe beide Programm Codes angeheftet und hoffe mir kann jemand helfen danke im voraus.
Python
from guizero import App, Text, TextBox, Box
import random
def random_number():
rand = random.randint(0, 100)
change_text.value = rand
app = App(title="Rahmen Belegung",layout="grid")
box1 = Box(app, layout="grid" , grid=[0,0])
box2 = Box(app, layout="grid" , grid=[1,0])
box3 = Box(app, layout="grid" , grid=[2,0])
box4 = Box(app, layout="grid" , grid=[3,0])
text = Text(box1, text="Rahmen 1: X=5 ; Y=00", grid=[0,1])
text = Text(box1, text="Rahmen 2: X=7 ; Y=10", grid=[0,3])
text = Text(box1, text="Rahmen 3: X=25; Y=13", grid=[0,5])
text = Text(box1, text="Rahmen 4: X=13; Y=22", grid=[0,7])
text = Text(box2, text="Entfernung:", grid=[1,0])
change_text = Text(box3, text="Here", grid=[0,8])
change_text.repeat(1000, random_number)
text = Text(box4, text="cm", grid=[1,0])
text = Text(box1, text="", grid=[0,0])
text = Text(box1, text="", grid=[0,2])
text = Text(box1, text="", grid=[0,4])
text = Text(box1, text="", grid=[0,6])
app.display()
Alles anzeigen
Python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO_TRIGGER = 12
GPIO_ECHO = 26
GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
GPIO.setup(GPIO_ECHO, GPIO.IN)
try:
while True:
def distanz():
GPIO.output(GPIO_TRIGGER, True)
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)
StartZeit = time.time()
StopZeit = time.time()
while GPIO.input(GPIO_ECHO) == 0:
StartZeit = time.time()
while GPIO.input(GPIO_ECHO) == 1:
StopZeit = time.time()
TimeElapsed = StopZeit - StartZeit
distanz = (TimeElapsed * 34300) / 2
return distanz
abstand = distanz()
import drivers
from time import sleep
display = drivers.Lcd()
a = abstand
a = round(a,2)
a = str(a)
print( "LCD Ausgabe")
display.lcd_display_string("Entfernung:", 1)
display.lcd_display_string(a + "cm", 2) # Write line of text to first line of display
sleep(1) # Give time for the message to be rea
display.lcd_clear() # Clear the display of any data
sleep(0.5) # Give time for the message to be read
except KeyboardInterrupt:
print("Cleaning up!")
display.lcd_clear()
Alles anzeigen