wheelsmanx

AI_CAR_GAUGE_REV1

Dec 11th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. #AI CAR GAUGE By Justin S Hagerty
  2. #Date 12/11/2016
  3. #Not Yet Opperational Just Test Files
  4. from tkinter import *
  5. import time
  6.  
  7. BUTTON_SIZE = 20
  8. NUM_BUTTON = 20
  9. MARGIN = 5
  10. WINDOW_H = MARGIN+((BUTTON_SIZE+MARGIN)*NUM_BUTTON)
  11. WINDOW_W = (2*MARGIN)+(BUTTON_SIZE)*40
  12.  
  13. #Set colours
  14. # R G B
  15. BLACK = '#000000'
  16. BRIGHTRED = '#ff0000'
  17. RED = '#9b0000'
  18.  
  19. LIGHTOFFON=[RED,BRIGHTRED]
  20. OFF = 0
  21. ON = 1
  22. colourBackground = BLACK
  23. colourButton = RED
  24. #Light Status
  25.  
  26. gasarray=[ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON,ON]
  27.  
  28. speedratio = 180/140
  29. changerate = .25
  30. datarate = .05
  31. yes = True
  32. on = "yes"
  33.  
  34. class startcar():
  35. gas = 0
  36. coolant_temp = 0
  37. speed = 0
  38. rpm = 0
  39. speed = (140 - speed) * speedratio
  40.  
  41. class car:
  42. gas = 2
  43. coolant_temp = 0
  44. if yes == True:
  45. speed = 10
  46. else:
  47. speed = 50
  48. speed = (140 - speed) * speedratio
  49. rpm = 0
  50.  
  51.  
  52. class caradjust():
  53. gas = 19
  54. coolant_temp = 0
  55. speed = 0
  56. rpm = 0
  57.  
  58.  
  59. def createDisplay():
  60. global tk, canvas, light, speedgauge
  61. # create the tk window - within which
  62. # everything else will be built.
  63. tk = Tk()
  64. #Add a canvas area ready for drawing on
  65. canvas = Canvas(tk, width=WINDOW_W, height=WINDOW_H, background=BLACK)
  66. canvas.pack()
  67. #Add some "lights" to the canvas
  68. light = []
  69. for i in range(0,NUM_BUTTON):
  70. x = MARGIN+((MARGIN+BUTTON_SIZE)*i)
  71. light.append(canvas.create_rectangle(MARGIN,x,
  72. BUTTON_SIZE+MARGIN,x+BUTTON_SIZE,fill=RED))
  73. if i == 0:
  74. canvas.create_text(MARGIN+BUTTON_SIZE*3,x*2,fill="white",text="FULL")
  75. if i == NUM_BUTTON-1:
  76. canvas.create_text(MARGIN+BUTTON_SIZE*3,x+(x/40),fill="white",text="EMPTY")
  77.  
  78. btn = Button(tk, text="Exit", command=terminate)
  79. btn.pack()
  80. btn2 = Button(tk, text="Yesss", command=gasgaugeupdate)
  81. btn2.pack()
  82. # Create keyboard bindings
  83. # Start the tk main-loop (this updates the tk display)
  84. tk.mainloop()
  85.  
  86. #def updateloop():
  87.  
  88.  
  89.  
  90. def gasgaugeupdate():
  91. B = 5
  92. A = 0
  93. while B < len(gasarray):
  94. B = B + 1
  95. A = 21 - B
  96. time.sleep(changerate)
  97. gasarray[A-1] = gastoggle(gasarray[A-1])
  98. canvas.itemconfig(light[A-1], fill=LIGHTOFFON[gasarray[A-1]])
  99. tk.update()
  100.  
  101. def gastoggle(value):
  102. value == ON
  103. return value
  104.  
  105. def toggle(value):
  106. if value == ON:
  107. value = OFF
  108. else:
  109. value = ON
  110. return value
  111.  
  112. def terminate():
  113. global tk
  114. tk.destroy()
  115.  
  116. def main():
  117. createDisplay()
  118.  
  119. if __name__ == '__main__':
  120. main()
Advertisement
Add Comment
Please, Sign In to add comment