SHARE
TWEET

Average Man's Temperature Monitor Display

AverageMan May 9th, 2014 371 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/python
  2.  
  3. #Imports
  4. import smbus
  5. import sys
  6. import getopt
  7. import time
  8. import os
  9.  
  10. #Set up SMBus
  11. bus = smbus.SMBus(0)  #for revision 2 board...use 1
  12.  
  13. #Set the I2C address
  14. address1 = 0x20
  15. address2 = 0x21
  16.  
  17. # Set both banks to outputs
  18. bus.write_byte_data(address1,0x00,0x00)
  19. bus.write_byte_data(address1,0x01,0x00)
  20. bus.write_byte_data(address2,0x00,0x00)
  21. bus.write_byte_data(address2,0x01,0x00)
  22.  
  23. #Bank mapping
  24. bank1 = 1 #Port A on 0x20
  25. bank2 = 2 #Port B on 0x20
  26. bank3 = 3 #Port A on 0x21        
  27.  
  28.  
  29. #More Bank Mapping
  30. def set_led(data,bank):
  31.   if bank == 1:
  32.    bus.write_byte_data(address1,0x12,data) #Bank 1 = MCP port A
  33.   if bank == 2:
  34.    bus.write_byte_data(address1,0x13,data) #Bank 2 = MCP port B
  35.   if bank == 3:
  36.    bus.write_byte_data(address2,0x12,data) #Bank 3 = MCP port A (second chip)
  37.  
  38. #Clear all Segments
  39.  
  40. set_led(0,bank1)
  41. set_led(0,bank2)
  42. set_led(0,bank3)
  43. time.sleep(1)
  44.  
  45. def main():
  46.  
  47.   #Define supporting variable
  48.  
  49.   timelastchecked = 0
  50.  
  51.   #Main Program
  52.      
  53.   while 1:
  54.     if time.time() >= timelastchecked:
  55.       timelastchecked = time.time()+3 #Check every 3 seconds
  56.       mytemp = ""
  57.       firstchar = ""
  58.       secondchar = ""
  59.       thirdchar = ""
  60.       f=os.popen("/opt/vc/bin/vcgencmd measure_temp") #Temperature command for terminal
  61.       for i in f.readlines():
  62.         mytemp += i
  63.         firstchar = mytemp[5:-6] #removes 5 characters from the front of the string, and 6 from the back
  64.         secondchar = mytemp[6:-5] #second character string
  65.         thirdchar = mytemp[8:-3] #third character string
  66.         while 1: #first segment
  67.           if firstchar == '0': #If first digit is 1
  68.             set_led(119,bank1)
  69.           elif firstchar == '1': #If first digit is 1
  70.             set_led(20,bank1)
  71.           elif firstchar == '2': #if not 1, try 2
  72.             set_led(79,bank1)
  73.           elif firstchar == '3': #if not 2, try 3
  74.             set_led(182,bank1)
  75.           elif firstchar == '4': #and so on...
  76.             set_led(212,bank1)
  77.           elif firstchar == '5':
  78.             set_led(230,bank1)
  79.           elif firstchar == '6':
  80.             set_led(231,bank1)
  81.           elif firstchar == '7': #and so on...
  82.             set_led(52,bank1)
  83.           elif firstchar == '8':
  84.             set_led(247,bank1)
  85.           elif firstchar == '9':
  86.             set_led(244,bank1)
  87.  
  88.           while 1: #second segment
  89.             if secondchar == '0':
  90.               set_led(127,bank2)
  91.             elif secondchar == '1':
  92.               set_led(28,bank2)
  93.             elif secondchar == '2':
  94.               set_led(187,bank2)
  95.             elif secondchar == '3':
  96.               set_led(190,bank2)
  97.             elif secondchar == '4':
  98.               set_led(220,bank2)
  99.             elif secondchar == '5':
  100.               set_led(238,bank2)
  101.             elif secondchar == '6':
  102.               set_led(239,bank2)
  103.             elif secondchar == '7':
  104.               set_led(60,bank2)
  105.             elif secondchar == '8':
  106.               set_led(255,bank2)
  107.             elif secondchar == '9':
  108.               set_led(252,bank2)
  109.  
  110.             while 1: #third segment
  111.               if thirdchar == '0':
  112.                 set_led(119,bank3)
  113.               elif thirdchar == '1':
  114.                 set_led(20,bank3)
  115.               elif thirdchar == '2':
  116.                 set_led(179,bank3)
  117.               elif thirdchar == '3':
  118.                 set_led(182,bank3)
  119.               elif thirdchar == '4':
  120.                 set_led(212,bank3)
  121.               elif thirdchar == '5':
  122.                 set_led(230,bank3)
  123.               elif thirdchar == '6':
  124.                 set_led(231,bank3)
  125.               elif thirdchar == '7':
  126.                 set_led(52,bank3)
  127.               elif thirdchar == '8':
  128.                 set_led(247,bank3)
  129.               elif thirdchar == '9':
  130.                 set_led(244,bank3)
  131.               time.sleep(2)
  132.               main()
  133.  
  134.  
  135. if __name__ == "__main__":
  136.    main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top