Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from urllib2 import Request, urlopen, URLError
- from time import sleep
- import smbus
- import sys
- import getopt
- import time
- import os
- #Set up SMBus
- bus = smbus.SMBus(1) #for revision 2 board...use 1
- #Set the I2C address
- address1 = 0x20
- address2 = 0x27
- # Set both banks to outputs
- bus.write_byte_data(address1,0x00,0x00)
- bus.write_byte_data(address1,0x01,0x00)
- bus.write_byte_data(address2,0x00,0x00)
- bus.write_byte_data(address2,0x01,0x00)
- #Bank mapping
- bank1 = 1 #Port A on 0x20
- bank2 = 2 #Port B on 0x20
- bank3 = 3 #Port A on 0x21
- #More Bank Mapping
- def set_led(data,bank):
- if bank == 1:
- bus.write_byte_data(address1,0x12,data) #Bank 1 = MCP port A
- if bank == 2:
- bus.write_byte_data(address1,0x13,data) #Bank 2 = MCP port B
- if bank == 3:
- bus.write_byte_data(address2,0x12,data) #Bank 3 = MCP port A (second chip)
- #Clear all Segments
- set_led(0,bank1)
- set_led(0,bank2)
- set_led(0,bank3)
- time.sleep(1)
- def scan():
- req = Request(someurl)
- try:
- response = urlopen(req)
- except URLError as e:
- if hasattr(e, 'reason'):
- print 'We failed to reach a server.'
- print 'Reason: ', e.reason
- elif hasattr(e, 'code'):
- print 'The server couldn\'t fulfill the request.'
- print 'Error code: ', e.code
- else:
- pcnt1 = ""
- pcnt2 = ""
- pcnt3 = ""
- the_page = response.readlines() # read each line of the html file into a variable 'the_page'
- for line in the_page: # iterate through the lines
- if 'data-goal' in line:
- pcnt1 = line[71:-44]
- pcnt2 = line[73:-42]
- pcnt3 = line[74:-41]
- #Print output
- print pcnt1
- print pcnt2
- print pcnt3
- print line
- #push output to eash segment display (there are 3 sgments)
- while 1: #first segment
- if pcnt1 == '0': #If first digit is 0
- set_led(119,bank1)
- elif pcnt1 == '1': #If first digit is 1
- set_led(20,bank1)
- elif pcnt1 == '2': #if not 1, try 2
- set_led(79,bank1)
- elif pcnt1 == '3': #if not 2, try 3
- set_led(182,bank1)
- elif pcnt1 == '4': #and so on...
- set_led(212,bank1)
- elif pcnt1 == '5':
- set_led(230,bank1)
- elif pcnt1 == '6':
- set_led(231,bank1)
- elif pcnt1 == '7': #and so on...
- set_led(52,bank1)
- elif pcnt1 == '8':
- set_led(247,bank1)
- elif pcnt1 == '9':
- set_led(244,bank1)
- while 1: #second segment
- if pcnt2 == '0':
- set_led(119,bank2)
- elif pcnt2 == '1':
- set_led(20,bank2)
- elif pcnt2 == '2':
- set_led(79,bank2)
- elif pcnt2 == '3':
- set_led(182,bank2)
- elif pcnt2 == '4':
- set_led(212,bank2)
- elif pcnt2 == '5':
- set_led(230,bank2)
- elif pcnt2 == '6':
- set_led(231,bank2)
- elif pcnt2 == '7':
- set_led(52,bank2)
- elif pcnt2 == '8':
- set_led(247,bank2)
- elif pcnt2 == '9':
- set_led(244,bank2)
- while 1: #third segment
- if pcnt3 == '0':
- set_led(119,bank3)
- elif pcnt3 == '1':
- set_led(20,bank3)
- elif pcnt3 == '2':
- set_led(179,bank3)
- elif pcnt3 == '3':
- set_led(182,bank3)
- elif pcnt3 == '4':
- set_led(212,bank3)
- elif pcnt3 == '5':
- set_led(230,bank3)
- elif pcnt3 == '6':
- set_led(231,bank3)
- elif pcnt3 == '7':
- set_led(52,bank3)
- elif pcnt3 == '8':
- set_led(247,bank3)
- elif pcnt3 == '9':
- set_led(244,bank3)
- time.sleep(2)
- while True:
- someurl= 'https://www.kickstarter.com/projects/955730101/protocam-raspberry-pi-a-b-camera-module-add-on-boa'
- scan() # scan the project page defined in someurl and get the data
- sleep(15) # wait 15 seconds
Advertisement
Add Comment
Please, Sign In to add comment