SHARE
TWEET

gui.py

richigarza Nov 10th, 2012 1,935 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. import serial
  4. import Tkinter as tk
  5. from Tkinter import *
  6.  
  7.  
  8. try:
  9.     arduino = serial.Serial( '/dev/ttyACM0', 9600 )
  10. except:
  11.     print "Cannot conect to the port"
  12.  
  13.  
  14. def LED1():
  15.     arduino.write('U')
  16.     print "Se encendio el led 1"
  17.  
  18. def LED2():
  19.     arduino.write('D')
  20.     print "Se encendio el led 2"
  21.  
  22. def LED3():
  23.     arduino.write('T')
  24.     print "Se encendio el led 3"
  25.  
  26. def LED4():
  27.     arduino.write('C')
  28.     print "Se encendio el led 4"
  29.  
  30. def motor():
  31.     arduino.write('M')
  32.     print "Se encendio el motor"
  33.    
  34.  
  35. root = Tk()
  36.  
  37. button1 = Button(root, text="LED 1", command=LED1)
  38. button1.grid(row=1, column=1)
  39. button2 = Button(root, text="LED 2", command=LED2)
  40. button2.grid(row=1, column=2)
  41. button3 = Button(root, text="LED 3", command=LED3)
  42. button3.grid(row=1, column=3)
  43. button4 = Button(root, text="LED 4", command=LED4)
  44. button4.grid(row=1, column=4)
  45. button5 = Button(root, text="Motor", command=motor)
  46. button5.grid(row=1, column=5)
  47.  
  48.  
  49. root.title('GUI de Leds')
  50. root.geometry("320x70")
  51. root.mainloop()
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top