#!/usr/bin/python
#--------------------------------------
Programme d'utiliser le moteur pas à pas pour tourner le bouton de chauffage de l'espace et hors
from Tkinter import *
import pickle
import sys
import time
import RPi.GPIO as GPIO
from datetime import datetime, timedelta
#import motor state
filename="Motor_State"
fileobject=open(filename,'rb')
marker=pickle.load(fileobject)
fileobject.close()
global stepper
GPIO.setmode(GPIO.BCM)
StepPins = [17,18,27,22]
for pin in StepPins:
GPIO.setup(pin,GPIO.OUT)
GPIO.output(pin, False)
time.sleep(0.5)
Seq = [[1,0,0,1],
[1,0,0,0],
[1,1,0,0],
[0,1,0,0],
[0,1,1,0],
[0,0,1,0],
[0,0,1,1],
[0,0,0,1]]
StepCounter=0
stepDir=0
StepCount=8
user=0
entrée #Get de l'utilisateur (actuellement de ne pas utiliser, en essayant de mettre en place GUI)Python Tkinter while ne pas arrêter
def CallInput():
global user
#print "StepMarker: ", (marker)
while True:
try:
user=int(input("Enter steps or -999 to quit:"))
except:
print("Sorry, invalid response.")
continue
if (user==999):
Schedule()
continue
if (user<0 or user>3000):
if (user==-999):
GPIO.cleanup()
quit()
print ("Cannot be less than 0 or greater than 3000.")
continue
else:
break
return user
état du moteur #Save
def SaveMarker(state):
fileobject=open(filename, 'wb')
pickle.dump(marker,fileobject)
fileobject.close()
print ("marker saved, Goodbye!!!")
#Schedule l'allumage du chauffe
def Schedule():
import datetime
print ("hello welcome to the Scheduler!")
print ("")
CallInput()
year=2017
month=datetime.datetime.now().strftime("%m")
hour=input("please enter the hour: ")
AMPM=str(raw_input("AM or PM: "))
minute=input("please enter the minute: ")
day=input("please enter the day: ")
if (AMPM=="PM" or AMPM== "pm"):
print (AMPM)
print ("hour: ", hour)
hour+=12
print ("hour: ", hour)
print (year, " ", month, " ", day, " ", hour, " ", minute)
starttime=datetime.datetime(int(year),int(month),int(day),hour,minute)
#if (hour<int(datetime.datetime.now().strptime("%h"))
#oneday=datetime.timedelta(days=+1)
while datetime.datetime.now() <starttime:
time.sleep(1)
print("youdidit",starttime, " ", datetime.datetime.now())
print("youdidit",starttime, " ", datetime.datetime.now())
RunMotor(user)
#GUI tentative
class Application(Frame):
""" A GUI application with three buttons. """
def __init__(self, master):
"""initialize the frame"""
Frame.__init__(self,master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.instruction = Label(self, text= marker)
self.instruction.grid(row=0, column=0, columnspan=2, sticky=W)
self.userinput= Entry(`enter code here`self)
self.userinput.grid(row=1, column=1, sticky=W)
self.submit_button=Button(self, text= "Submit", command=self.reveal)
self.submit_button.grid(row=2, column=0, sticky=W)
self.text= Text(self, width=35, height=5, wrap=WORD)
self.text.grid(row=3, column=0, columnspan=2, sticky=W)
def reveal(self):
stepper=self.userinput.get()
#code pour le tournage du moteur
global StepCount
global StepCounter
global StepDir
global marker
Aide! Cette boucle while finit en quelque sorte jusqu'à l'infini ???????????? Noob ici. Cela fonctionne en dehors de Tkinter. J'ai littéralement copié et collé le code et il exécute juste pour toujours après avoir cliqué sur le bouton soumettre, le moteur continue à tourner et ne s'arrête pas. Il devrait casser quand Stepper = marqueur droit?
while stepper!=marker:
print StepCounter,
print Seq[StepCounter], "stepper: ", (stepper), "Marker: ", (marker)
if (stepper<marker):
stepDir=-1
else:
stepDir=1
for pin in range(0, 4):
xpin = StepPins[pin]
if Seq[StepCounter][pin]!=0:
GPIO.output(xpin, True)
else:
GPIO.output(xpin, False)
marker+=stepDir
StepCounter += stepDir
# If we reach the end of the sequence
# start again
if (StepCounter>=StepCount):
StepCounter = 0
if (StepCounter<0):
StepCounter = StepCount+stepDir
# Wait before moving on
time.sleep(.006)
for pin in StepPins:
GPIO.output(pin, False)
SaveMarker(marker)
if content == marker:
message = "content" + str(content)
else:
print "success"
message ="marker" + str(marker) +"content" + str(content)
self.text.insert(0.0, message)
root = Tk()
root.title("Passwords")
root.geometry("250x150")
app=Application(root)
root.mainloop()
# Start main loop
#Old code
#while True:
# CallInput()
# RunMotor(user)
import atexit
atexit.register(SaveMarker)
Vous avez posté un code beaucoup trop. Veuillez réduire le code à un [mcve], puis montrez les étapes que vous avez effectuées pour le déboguer. –