Advertisement
Venaci

LCD Threading

May 22nd, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.14 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import time,threading,sys
  4. import mraa
  5. import SSD1306
  6. import Image
  7. import ImageDraw
  8. import ImageFont
  9. import subprocess
  10. #----Import All Needed Modules
  11. disp = SSD1306.SSD1306_128_64()
  12. disp.begin()
  13. disp.clear()
  14. disp.display()
  15. #----Init, do not touch before here
  16.  
  17. width = disp.width
  18. height = disp.height
  19. image = Image.new('1', (width, height))
  20. draw = ImageDraw.Draw(image)
  21. #----Prepare and Clear Screen
  22. font1 = ImageFont.truetype("fonts/Sarpanch.otf", 20)
  23. font2 = ImageFont.truetype('fonts/Naughty Cartoons.ttf',10)
  24. #----Sets Fonts
  25.  
  26. #
  27. #----Can draw static area here
  28. #
  29. #_____________________________________
  30.  
  31. #----Screen Updates after here
  32. i=0
  33. #Loop for updating screen numbers
  34. def screenDraw():
  35.  while 1:
  36.     global i
  37.     i += 1
  38.     mcuTemp = int(subprocess.check_output("cat /sys/class/thermal/thermal_zone1/temp", shell=True).rstrip())/1000
  39. #   mcuTemp = int(subprocess.check_output("cat /sys/class/thermal/thermal_zone1/temp", shell=True).rstrip())
  40.     cpu1Temp = int(subprocess.check_output("cat /sys/class/thermal/thermal_zone3/temp", shell=True).rstrip())/1000
  41.     cpu2Temp = int(subprocess.check_output("cat /sys/class/thermal/thermal_zone4/temp", shell=True).rstrip())/1000
  42.  
  43.         print "ID#:",i," Pot:"
  44.     print "CPU1:",cpu1Temp," CPU2:",cpu2Temp," MCU:",mcuTemp
  45.  
  46.     draw.rectangle([0,-8,128,128], fill=0, outline=0)  
  47.     draw.text((0,-8),"Ba:"+str(i),  font=ImageFont.truetype("fonts/Sarpanch.otf", 18), fill=255)
  48.     draw.text((70,-8)," MC:"+str(mcuTemp),  font=ImageFont.truetype("fonts/Sarpanch.otf", 18), fill=255)
  49.     draw.text((63,12)," CPU1: "+str(cpu1Temp),  font=ImageFont.truetype("fonts/Sarpanch.otf", 15), fill=255)
  50.     draw.text((59,26)," CPU2: "+str(cpu2Temp),  font=ImageFont.truetype("fonts/Sarpanch.otf", 15), fill=255)
  51.  
  52.  
  53.     # Display image.
  54.     disp.image(image)
  55.     disp.display()
  56.  
  57.  
  58. def senPotRead():
  59. #   potVal = mraa.Aio(5).read()
  60. #LCD Screen works until above this is uncommented
  61. #Terminal still scrolls, showing output
  62.     time.sleep(5)
  63.  
  64. #________________________________
  65.  
  66. #----Call for Threads to start
  67.  
  68. def runtime():
  69.     threading.Timer(0, screenDraw).start()
  70.     threading.Timer(0, senPotRead).start()
  71.  
  72. runtime()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement