Last active
September 19, 2016 14:09
-
-
Save Robotonics/1cecdf51cffaadbaa8e18895f90aec29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wx | |
import RPi.GPIO as GPIO | |
# Initialise GPIO's for Rover | |
GPIO.setwarnings(False) | |
PINS=[18,23,24,25] | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(PINS,GPIO.OUT) | |
class control(wx.Frame): | |
def __init__(self, parent, title): | |
super(control, self).__init__(parent, title = title,size = (600,400)) | |
panel = wx.Panel(self) | |
vbox = wx.BoxSizer(wx.VERTICAL) | |
bmp = wx.Bitmap("up.png", wx.BITMAP_TYPE_ANY) | |
self.forwardbtn = wx.BitmapButton(panel, id = wx.ID_ANY, bitmap = bmp, | |
size = (bmp.GetWidth()+10, bmp.GetHeight()+10)) | |
bmp2 = wx.Bitmap("right.png", wx.BITMAP_TYPE_ANY) | |
self.rightbtn = wx.BitmapButton(panel, id = wx.ID_ANY, bitmap = bmp2, | |
size = (bmp2.GetWidth()+10, bmp2.GetHeight()+10)) | |
bmp3 = wx.Bitmap("left.png", wx.BITMAP_TYPE_ANY) | |
self.leftbtn = wx.BitmapButton(panel, id = wx.ID_ANY, bitmap = bmp3, | |
size = (bmp3.GetWidth()+10, bmp3.GetHeight()+10)) | |
bmp4 = wx.Bitmap("down.png", wx.BITMAP_TYPE_ANY) | |
self.reversebtn = wx.BitmapButton(panel, id = wx.ID_ANY, bitmap = bmp4, | |
size = (bmp4.GetWidth()+10, bmp4.GetHeight()+10)) | |
bmp5 = wx.Bitmap("stop.png", wx.BITMAP_TYPE_ANY) | |
self.stopbtn = wx.BitmapButton(panel, id = wx.ID_ANY, bitmap = bmp5, | |
size = (bmp5.GetWidth()+10, bmp5.GetHeight()+10)) | |
hbox = wx.BoxSizer(wx.HORIZONTAL) | |
hbox.Add(self.forwardbtn,0,wx.ALIGN_TOP|wx.ALIGN_CENTER) | |
self.forwardbtn.Bind(wx.EVT_BUTTON,self.Forward) | |
self.forwardbtn.SetLabel("Forward") | |
hbox.Add(self.leftbtn,0,wx.TOP,150) | |
self.leftbtn.Bind(wx.EVT_BUTTON,self.Left) | |
self.leftbtn.SetLabel("Left") | |
hbox.Add(self.stopbtn,0,wx.TOP,150) | |
self.stopbtn.Bind(wx.EVT_BUTTON,self.Stop) | |
self.stopbtn.SetLabel("Stop") | |
hbox.Add(self.rightbtn,0,wx.TOP,150) | |
self.rightbtn.Bind(wx.EVT_BUTTON,self.Right) | |
self.rightbtn.SetLabel("Right") | |
hbox.Add(self.reversebtn,0,wx.ALIGN_BOTTOM|wx.ALIGN_CENTER) | |
self.reversebtn.Bind(wx.EVT_BUTTON,self.Reverse) | |
self.reversebtn.SetLabel("Reverse") | |
vbox.Add(hbox,1,wx.ALIGN_CENTER) | |
panel.SetSizer(vbox) | |
self.Centre() | |
self.Show() | |
self.Fit() | |
# Setup direction control output functions | |
def Reverse(self, event=None): | |
GPIO.output(PINS,(GPIO.HIGH,GPIO.LOW,GPIO.LOW,GPIO.HIGH)) | |
def Stop(self, event=None): | |
GPIO.output(PINS,(GPIO.LOW,GPIO.LOW,GPIO.LOW,GPIO.LOW)) | |
def Forward(self, event=None): | |
GPIO.output(PINS,(GPIO.LOW,GPIO.HIGH,GPIO.HIGH,GPIO.LOW)) | |
def Left(self, event=None): | |
GPIO.output(PINS,(GPIO.LOW,GPIO.HIGH,GPIO.LOW,GPIO.HIGH)) | |
def Right(self, event=None): | |
GPIO.output(PINS,(GPIO.HIGH,GPIO.LOW,GPIO.HIGH,GPIO.LOW)) | |
app = wx.App() | |
control(None, 'Rover Control Panel') | |
app.MainLoop() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment