Guest User

Messy Draft KS Tracker for temp monitor board

a guest
Jan 13th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.20 KB | None | 0 0
  1. from urllib2 import Request, urlopen, URLError
  2. from time import sleep
  3. import smbus
  4. import sys
  5. import getopt
  6. import time
  7. import os
  8.  
  9. #Set up SMBus
  10. bus = smbus.SMBus(1)  #for revision 2 board...use 1
  11.  
  12. #Set the I2C address
  13. address1 = 0x20
  14. address2 = 0x27
  15.  
  16. # Set both banks to outputs
  17. bus.write_byte_data(address1,0x00,0x00)
  18. bus.write_byte_data(address1,0x01,0x00)
  19. bus.write_byte_data(address2,0x00,0x00)
  20. bus.write_byte_data(address2,0x01,0x00)
  21.  
  22. #Bank mapping
  23. bank1 = 1 #Port A on 0x20
  24. bank2 = 2 #Port B on 0x20
  25. bank3 = 3 #Port A on 0x21        
  26.  
  27.  
  28. #More Bank Mapping
  29. def set_led(data,bank):
  30.   if bank == 1:
  31.     bus.write_byte_data(address1,0x12,data) #Bank 1 = MCP port A
  32.   if bank == 2:
  33.     bus.write_byte_data(address1,0x13,data) #Bank 2 = MCP port B
  34.   if bank == 3:
  35.     bus.write_byte_data(address2,0x12,data) #Bank 3 = MCP port A (second chip)
  36.  
  37. #Clear all Segments
  38.  
  39. set_led(0,bank1)
  40. set_led(0,bank2)
  41. set_led(0,bank3)
  42. time.sleep(1)
  43.  
  44. def scan():
  45.   req = Request(someurl)
  46.   try:
  47.     response = urlopen(req)
  48.   except URLError as e:
  49.     if hasattr(e, 'reason'):
  50.       print 'We failed to reach a server.'
  51.       print 'Reason: ', e.reason
  52.     elif hasattr(e, 'code'):
  53.       print 'The server couldn\'t fulfill the request.'
  54.       print 'Error code: ', e.code
  55.   else:
  56.     pcnt1 = ""
  57.     pcnt2 = ""
  58.     pcnt3 = ""
  59.     the_page = response.readlines()     # read each line of the html file into a variable 'the_page'
  60.     for line in the_page:               # iterate through the lines
  61.       if 'data-goal' in line:
  62.         pcnt1 = line[71:-44]
  63.         pcnt2 = line[73:-42]
  64.         pcnt3 = line[74:-41]
  65.  
  66.         #Print output
  67.         print pcnt1
  68.         print pcnt2
  69.         print pcnt3
  70.         print line
  71.  
  72.         #push output to eash segment display (there are 3 sgments)
  73.         while 1: #first segment
  74.           if pcnt1 == '0': #If first digit is 0
  75.             set_led(119,bank1)
  76.           elif pcnt1 == '1': #If first digit is 1
  77.             set_led(20,bank1)
  78.           elif pcnt1 == '2': #if not 1, try 2
  79.             set_led(79,bank1)
  80.           elif pcnt1 == '3': #if not 2, try 3
  81.             set_led(182,bank1)
  82.           elif pcnt1 == '4': #and so on...
  83.             set_led(212,bank1)
  84.           elif pcnt1 == '5':
  85.             set_led(230,bank1)
  86.           elif pcnt1 == '6':
  87.             set_led(231,bank1)
  88.           elif pcnt1 == '7': #and so on...
  89.             set_led(52,bank1)
  90.           elif pcnt1 == '8':
  91.             set_led(247,bank1)
  92.           elif pcnt1 == '9':
  93.             set_led(244,bank1)
  94.  
  95.           while 1: #second segment
  96.             if pcnt2 == '0':
  97.               set_led(119,bank2)
  98.             elif pcnt2 == '1':
  99.               set_led(20,bank2)
  100.             elif pcnt2 == '2':
  101.               set_led(79,bank2)
  102.             elif pcnt2 == '3':
  103.               set_led(182,bank2)
  104.             elif pcnt2 == '4':
  105.               set_led(212,bank2)
  106.             elif pcnt2 == '5':
  107.               set_led(230,bank2)
  108.             elif pcnt2 == '6':
  109.               set_led(231,bank2)
  110.             elif pcnt2 == '7':
  111.               set_led(52,bank2)
  112.             elif pcnt2 == '8':
  113.               set_led(247,bank2)
  114.             elif pcnt2 == '9':
  115.               set_led(244,bank2)
  116.  
  117.             while 1: #third segment
  118.               if pcnt3 == '0':
  119.                 set_led(119,bank3)
  120.               elif pcnt3 == '1':
  121.                 set_led(20,bank3)
  122.               elif pcnt3 == '2':
  123.                 set_led(179,bank3)
  124.               elif pcnt3 == '3':
  125.                 set_led(182,bank3)
  126.               elif pcnt3 == '4':
  127.                 set_led(212,bank3)
  128.               elif pcnt3 == '5':
  129.                 set_led(230,bank3)
  130.               elif pcnt3 == '6':
  131.                 set_led(231,bank3)
  132.               elif pcnt3 == '7':
  133.                 set_led(52,bank3)
  134.               elif pcnt3 == '8':
  135.                 set_led(247,bank3)
  136.               elif pcnt3 == '9':
  137.                 set_led(244,bank3)
  138.   time.sleep(2)
  139.  
  140. while True:
  141.   someurl= 'https://www.kickstarter.com/projects/955730101/protocam-raspberry-pi-a-b-camera-module-add-on-boa'
  142.   scan()          # scan the project page defined in someurl and get the data
  143.   sleep(15)       # wait 15 seconds
Advertisement
Add Comment
Please, Sign In to add comment