Skip to content

Instantly share code, notes, and snippets.

@baskaufs
Created February 24, 2018 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baskaufs/3ca84908d5fc88865957929700549b1e to your computer and use it in GitHub Desktop.
Save baskaufs/3ca84908d5fc88865957929700549b1e to your computer and use it in GitHub Desktop.
Froggy the Robot controller via Raspberry Pi
# Steve Baskauf 2018-02-23 Freely available under a GNU GPLv3 license.
#libraries for GUI interface
import tkinter
from tkinter import *
from tkinter import ttk
from gpiozero import LED, Button
from time import sleep
led17 = LED(17) # right wheel direction, off=forward, on=backward
led27 = LED(27) # wheel power, off=off, on=on
led22 = LED(22) # left wheel direction, off=forward, on=backward
led23 = LED(23) # tongue power, off=off, on=on
led24 = LED(24) # tongue direction, off=out, on=in
root = Tk()
# this sets up the characteristics of the window
root.title("Froggy robot controller")
mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
def tongueOutButtonClick():
tongueOut()
gitToBaseButton = ttk.Button(mainframe, text = "tongue out", width = 30, command = lambda: tongueOutButtonClick() )
gitToBaseButton.grid(column=4, row=8, sticky=W)
def tongueInButtonClick():
tongueIn()
gitToBaseButton = ttk.Button(mainframe, text = "tongue in", width = 30, command = lambda: tongueInButtonClick() )
gitToBaseButton.grid(column=4, row=10, sticky=W)
def forwardButtonClick():
forward()
baseToTripleButton = ttk.Button(mainframe, text = "forward", width = 30, command = lambda: forwardButtonClick() )
baseToTripleButton.grid(column=4, row=12, sticky=W)
def backwardButtonClick():
backward()
moveFileButton = ttk.Button(mainframe, text = "backward", width = 30, command = lambda: backwardButtonClick() )
moveFileButton.grid(column=4, row=14, sticky=W)
def turnRightButtonClick():
turnRight()
dropGraphButton = ttk.Button(mainframe, text = "turn right", width = 30, command = lambda: turnRightButtonClick() )
dropGraphButton.grid(column=4, row=16, sticky=W)
def turnLeftButtonClick():
turnLeft()
dropGraphButton = ttk.Button(mainframe, text = "turn left", width = 30, command = lambda: turnLeftButtonClick() )
dropGraphButton.grid(column=4, row=18, sticky=W)
def on(pin):
text = pin + ' on'
led27.on() ## Turn on GPIO pin
print(text)
def off(pin):
text = pin + ' off'
led27.off() ## Turn off GPIO pin
print(text)
def tongueOut():
print("tongue out")
led23.on()
sleep(.6)
led23.off()
def tongueIn():
print("tongue in")
led24.on()
led23.on()
sleep(.6)
led23.off()
led24.off()
def forward():
print("forward")
led27.on()
sleep(1)
led27.off()
def backward():
print("backward")
led17.on()
led22.on()
led27.on()
sleep(1)
led27.off()
led22.off()
led17.off()
def turnRight():
print("turn right")
led17.on()
led27.on()
sleep(1)
led27.off()
led17.off()
def turnLeft():
print("turn left")
led22.on()
led27.on()
sleep(1)
led27.off()
led22.off()
def main():
root.mainloop()
if __name__=="__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment