Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as gpio
- import time
- import sys
- import Tkinter as tk
- def init(): # Die Initialisierung der GPIO Pins
- gpio.setmode(gpio.BOARD)
- gpio.setup(7, gpio.OUT)
- gpio.setup(11, gpio.OUT)
- gpio.setup(13, gpio.OUT)
- gpio.setup(15, gpio.OUT)
- def vorwaerts(tf): # Methode zum geradeaus fahren
- gpio.output(7, False)
- gpio.output(11, True)
- gpio.output(13, True)
- gpio.output(15, False)
- time.sleep(tf)
- gpio.cleanup()
- def ruckwaerts(tf): # Methode zum Rueckwaerts fahren
- gpio.output(7, True)
- gpio.output(11, False)
- gpio.output(13, False)
- gpio.output(15, True)
- time.sleep(tf)
- gpio.cleanup()
- def fahre_links(tf): # Methode zum links fahren
- gpio.output(7, True)
- gpio.output(11, True)
- gpio.output(13, True)
- gpio.output(15, False)
- time.sleep(tf)
- gpio.cleanup()
- def fahre_rechts(tf): #Methode zum rechts fahren
- gpio.output(7, False)
- gpio.output(11, True)
- gpio.output(13, False)
- gpio.output(15, False)
- time.sleep(tf)
- gpio.cleanup()
- def schwenke_links(tf): #Methode zum Links schwenken
- gpio.output(7, True)
- gpio.output(11, False)
- gpio.output(13, True)
- gpio.output(15, False)
- time.sleep(tf)
- gpio.cleanup()
- def schwenke_rechts(tf): #Methode zum Rechts schwenken
- gpio.output(7, False)
- gpio.output(11, True)
- gpio.output(13, False)
- gpio.output(15, True)
- time.sleep(tf)
- gpio.cleanup()
- def tasteneingabe(eingabe):
- init()
- print 'Key:', eingabe.char
- tastendruck = eingabe.char
- sleep_time = 0.030
- if tastendruck.lower() == 'w':
- vorwaerts(sleep_time)
- elif tastendruck.lower() == 's':
- ruckwaerts(sleep_time)
- elif tastendruck.lower() == 'a':
- fahre_links(sleep_time)
- elif tastendruck.lower() == 'd':
- fahre_rechts(sleep_time)
- elif tastendruck.lower() == 'q':
- schwenke_links(sleep_time)
- elif tastendruck.lower() == 'e':
- schwenke_rechts(sleep_time)
- command = tk.Tk()
- command.bind('<Taste gedrueckt>', tasteneingabe)
- command.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement