本文整理汇总了Python中Adafruit_LEDBackpack.LEDBackpack类的典型用法代码示例。如果您正苦于以下问题:Python LEDBackpack类的具体用法?Python LEDBackpack怎么用?Python LEDBackpack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LEDBackpack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
class Display:
disp = None
# Constructor
def __init__(self, address=0x70, debug=False):
if (debug):
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
self.disp = LEDBackpack(address=address, debug=debug)
def writeChar(self, charNumber, value):
global DIGIT_VALUES
self.setBufferRow(charNumber, DIGIT_VALUES[value])
def setBufferRow(self, charNumber, value):
self.disp.setBufferRow(charNumber, value)
示例2: table
class SevenSegment:
disp = None
# Hexadecimal character lookup table (row 1 = 0..9, row 2 = A..F)
digits = [ 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, \
0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71 ]
# Constructor
def __init__(self, address=0x70, debug=False):
if (debug):
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
self.disp = LEDBackpack(address=address, debug=debug)
def clear(self):
self.disp.clear()
def setBrightness(self, bright):
self.setBrightness(bright)
def writeDigitRaw(self, charNumber, value):
"Sets a digit using the raw 16-bit value"
if (charNumber > 7):
return
# Set the appropriate digit
self.disp.setBufferRow(charNumber, value)
def writeDigit(self, charNumber, value, dot=False):
"Sets a single decimal or hexademical value (0..9 and A..F)"
if (charNumber > 7):
return
if (value > 0xF):
return
# Set the appropriate digit
self.disp.setBufferRow(charNumber, self.digits[value] | (dot << 7))
def setColon(self, state=True):
"Enables or disables the colon character"
# Warning: This function assumes that the colon is character '2',
# which is the case on 4 char displays, but may need to be modified
# if another display type is used
if (state):
self.disp.setBufferRow(2, 0xFFFF)
else:
self.disp.setBufferRow(2, 0)
示例3: table
class SevenSegment:
disp = None
invert = False
# Hexadecimal character lookup table (row 1 = 0..9, row 2 = A..F)
digits = [ 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, \
0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71 ]
# The same, but upside-down
idigits = [ 0x3F, 0x30, 0x5B, 0x79, 0x74, 0x6D, 0x6F, 0x38, 0x7F, 0x7D, \
0x7E, 0x67, 0x0F, 0x73, 0x4F, 0x4E ]
# Constructor
def __init__(self, address=0x70, debug=False):
if (debug):
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
self.disp = LEDBackpack(address=address, debug=debug)
def writeDigitRaw(self, charNumber, value):
"Sets a digit using the raw 16-bit value"
if (charNumber > 7):
return
# Set the appropriate digit
self.disp.setBufferRow(charNumber, value)
def writeDigit(self, charNumber, value, dot=False):
"Sets a single decimal or hexademical value (0..9 and A..F)"
if (charNumber > 7):
return
if (value > 0xF):
return
# Decide which digit set to use: check self.invert
d = self.idigits[value] if self.invert else self.digits[value]
# If inverted, also reverse the character positions
c = (4-charNumber) if self.invert else charNumber
# Set the appropriate digit
self.disp.setBufferRow(c, d | (dot << 7))
def setColon(self, state=True):
"Enables or disables the colon character"
# Warning: This function assumes that the colon is character '2',
# which is the case on 4 char displays, but may need to be modified
# if another display type is used
# This sets all non-digit LEDs. Change (2,0xFFFF) to (2,2) to just
# set colon on the 1.2" 7-Segment display.
if (state):
self.disp.setBufferRow(2, 0xFFFF)
else:
self.disp.setBufferRow(2, 0)
示例4: __init__
class EightByEight:
disp = None
# Constructor
def __init__(self, address=0x70, debug=False):
if (debug):
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
self.disp = LEDBackpack(address=address, debug=debug)
def writeRowRaw(self, charNumber, value):
"Sets a row of pixels using a raw 16-bit value"
if (charNumber > 7):
return
# Set the appropriate row
self.disp.setBufferRow(charNumber, value)
def getBuffer(self):
return self.disp.getBuffer()
def clearPixel(self, x, y):
"A wrapper function to clear pixels (purely cosmetic)"
self.setPixel(x, y, 0)
def setPixel(self, x, y, color=1):
"Sets a single pixel"
if (x >= 8):
return
if (y >= 8):
return
x += 7 # ATTN: This might be a bug? On the color matrix, this causes x=0 to draw on the last line instead of the first.
x %= 8
# Set the appropriate pixel
buffer = self.disp.getBuffer()
if (color):
self.disp.setBufferRow(y, buffer[y] | 1 << x)
else:
self.disp.setBufferRow(y, buffer[y] & ~(1 << x))
def clear(self):
"Clears the entire display"
self.disp.clear()
示例5: __init__
class EightByEight:
disp = None
# Constructor
def __init__(self, address=0x70, bus=Adafruit_I2C.getPiI2CBusNumber(), debug=False):
if (debug):
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
self.disp = LEDBackpack(address=address, bus=bus, debug=debug)
def writeRowRaw(self, charNumber, value):
"Sets a row of pixels using a raw 16-bit value"
if (charNumber > 7):
return
# Set the appropriate row
self.disp.setBufferRow(charNumber, value)
def clearPixel(self, x, y):
"A wrapper function to clear pixels (purely cosmetic)"
self.setPixel(x, y, 0)
def setPixel(self, x, y, color=1):
"Sets a single pixel"
if (x >= 8):
return
if (y >= 8):
return
x += 7
x %= 8
# Set the appropriate pixel
buffer = self.disp.getBuffer()
if (color):
self.disp.setBufferRow(y, buffer[y] | 1 << x)
else:
self.disp.setBufferRow(y, buffer[y] & ~(1 << x))
def clear(self):
"Clears the entire display"
self.disp.clear()
示例6: __init__
class Bargraph:
disp = None
LED_OFF = 0
LED_RED = 1
LED_GREEN = 2
LED_YELLOW = 3
# Constructor
def __init__(self, address=0x70, debug=False):
self.debug = debug
if self.debug:
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
self.disp = LEDBackpack(address=address, debug=debug)
def setLed(self, bar, color):
if bar > 24:
return
if color > 3:
return
if bar < 12:
c = bar / 4
else:
c = (bar - 12) / 4
a = bar % 4;
if bar >= 12:
a += 4;
if self.debug:
print "Ano = %d Cath %d" % (a, c)
bufRow = self.disp.getBufferRow(c) & ~((1 << a) | (1 << (a+8))) # turn off the LED
if color == self.LED_RED:
self.disp.setBufferRow(c, bufRow | (1 << a))
elif color == self.LED_YELLOW:
self.disp.setBufferRow(c, bufRow | (1 << a) | (1 << (a+8)))
elif color == self.LED_GREEN:
self.disp.setBufferRow(c, bufRow | 1 << (a+8))
示例7: Alphanumeric
#.........这里部分代码省略.........
0b0000000010001111, # 3
0b0000000011100110, # 4
0b0010000001101001, # 5
0b0000000011111101, # 6
0b0000000000000111, # 7
0b0000000011111111, # 8
0b0000000011101111, # 9
0b0001001000000000, # :
0b0000101000000000, # ;
0b0010010000000000, # <
0b0000000011001000, # =
0b0000100100000000, # >
0b0001000010000011, # ?
0b0000001010111011, # @
0b0000000011110111, # A
0b0001001010001111, # B
0b0000000000111001, # C
0b0001001000001111, # D
0b0000000011111001, # E
0b0000000001110001, # F
0b0000000010111101, # G
0b0000000011110110, # H
0b0001001000000000, # I
0b0000000000011110, # J
0b0010010001110000, # K
0b0000000000111000, # L
0b0000010100110110, # M
0b0010000100110110, # N
0b0000000000111111, # O
0b0000000011110011, # P
0b0010000000111111, # Q
0b0010000011110011, # R
0b0000000011101101, # S
0b0001001000000001, # T
0b0000000000111110, # U
0b0000110000110000, # V
0b0010100000110110, # W
0b0010110100000000, # X
0b0001010100000000, # Y
0b0000110000001001, # Z
0b0000000000111001, # [
0b0010000100000000, #
0b0000000000001111, # ]
0b0000110000000011, # ^
0b0000000000001000, # _
0b0000000100000000, # `
0b0001000001011000, # a
0b0010000001111000, # b
0b0000000011011000, # c
0b0000100010001110, # d
0b0000100001011000, # e
0b0000000001110001, # f
0b0000010010001110, # g
0b0001000001110000, # h
0b0001000000000000, # i
0b0000000000001110, # j
0b0011011000000000, # k
0b0000000000110000, # l
0b0001000011010100, # m
0b0001000001010000, # n
0b0000000011011100, # o
0b0000000101110000, # p
0b0000010010000110, # q
0b0000000001010000, # r
0b0010000010001000, # s
0b0000000001111000, # t
0b0000000000011100, # u
0b0010000000000100, # v
0b0010100000010100, # w
0b0010100011000000, # x
0b0010000000001100, # y
0b0000100001001000, # z
0b0000100101001001, # {
0b0001001000000000, # |
0b0010010010001001, # }
0b0000010100100000, # ~
0b0011111111111111]
special = dict(degree= 0b0000000011100011, cone=0b0010100000001000)
def __init__(self, address=0x70, debug=False):
self.disp = LEDBackpack(address=address, debug=debug)
def writeCharRaw(self, charNumber, value):
"Sets a digit using the raw 16-bit value"
if (charNumber > 4):
return
# Set the appropriate digit
self.disp.setBufferRow(charNumber, value)
def writeChar(self, charNumber, value, dot=False):
"Sets a single decimal or hexademical value (0..9 and A..F)"
if (charNumber > 4):
return
if value in self.special:
value = self.special[value]
else:
value = self.lut[ord(value)]
# Set the appropriate digit
self.disp.setBufferRow(charNumber, value | (dot << 14))
示例8: get_datastream
# function to return a datastream object. This either creates a new datastream,
# or returns an existing one
def get_datastream(feed):
try:
datastream = feed.datastreams.get("external_temp")
return datastream
except:
datastream = feed.datastreams.create("external_temp", tags="temp_01")
return datastream
# ===========================================================================
# Clock Example
# ===========================================================================
led=LEDBackpack(address=0x70)
segment = SevenSegment(address=0x70)
try:
interval=int(sys.argv[1])
except:
print 'Interval required'
sys.exit(1)
daybrightness=15
nightbrightness=5
minbrightness=1
maxbrightness=15
示例9: SevenSegment
__author__ = 'Justin'
# ===========================================================================
# Main clock program
# ===========================================================================
import time
import datetime
from Adafruit_7Segment import SevenSegment
from Adafruit_LEDBackpack import LEDBackpack
from clock_API import ClockAPI
print "Press CTRL+Z to exit"
segment = SevenSegment(address=0x70)
backpack = LEDBackpack()
data = ClockAPI()
backpack.setBrightness(0)
API_data = data.getWeatherCondition('seattle', 'F')
temp = API_data[2]
print datetime.datetime.now()
print API_data
print temp
# Continually update the time on a 4 char, 7-segment display
# while True:
示例10: SevenSegment
#!/usr/bin/python
# tsp_timer
#
# set timer display and handle button press
import RPi.GPIO as GPIO
import time
import datetime
from Adafruit_7Segment import SevenSegment
from Adafruit_LEDBackpack import LEDBackpack
segment = SevenSegment(address=0x73)
backpack = LEDBackpack(address=0x73)
backpack.setBrightness(15)
BUTTON_GPIO = 17
# states constants
STOP = 1
RUN = 2
HOLD = 3
timer_state = STOP
last_timer_state = STOP
hold_time = 0
timer_start = datetime.datetime.now()
run_time = datetime.timedelta(0)
GPIO.setmode(GPIO.BCM)
示例11: __init__
def __init__(self, address=0x70, debug=False):
if (debug):
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
LEDBackpack.__init__(self, 8, 8, address, debug)
self.rotation = 0
示例12: ColorEightByEight
class ColorEightByEight(EightByEight):
disp = None
# Constructor
def __init__(self, address=0x70, debug=False):
if (debug):
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
self.disp = LEDBackpack(address=address, debug=debug)
def getBufferValue(self, i):
buffer = self.disp.getBuffer()
return buffer[i]
def setPixel(self, x, y, color=1):
"Sets a single pixel"
if (x >= 8):
return
if (y >= 8):
return
x %= 8
# Set the appropriate pixel
buffer = self.disp.getBuffer()
# TODO : Named color constants?
# ATNN : This code was mostly taken from the arduino code, but with the addition of clearing the other bit when setting red or green.
# The arduino code does not do that, and might have the bug where if you draw red or green, then the other color, it actually draws yellow.
# The bug doesn't show up in the examples because it's always clearing.
if (color == 1):
self.disp.setBufferRow(y, (buffer[y] | (1 << x)) & ~(1 << (x+8)) )
elif (color == 2):
self.disp.setBufferRow(y, (buffer[y] | 1 << (x+8)) & ~(1 << x) )
elif (color == 3):
self.disp.setBufferRow(y, buffer[y] | (1 << (x+8)) | (1 << x) )
else:
self.disp.setBufferRow(y, buffer[y] & ~(1 << x) & ~(1 << (x+8)) )
def setBrightness(self, brightness):
"Sets the brightness level from 0..15"
self.disp.setBrightness(brightness)
def setBlinkRate(self, blinkRate):
self.disp.setBrightness(blinkRate)
def clear(self):
"Clears the entire display"
self.disp.clear()
示例13: LEDBackpack
#!/usr/bin/python
import time
import datetime
from Adafruit_7Segment import SevenSegment
from Adafruit_LEDBackpack import LEDBackpack
backpack = LEDBackpack(address=0x74)
backpack.setBrightness(15)
# ===========================================================================
# Clock Example
# ===========================================================================
segment = SevenSegment(address=0x74)
# Continually update the time on a 4 char, 7-segment display
while(True):
now = datetime.datetime.now()
hour = now.hour
minute = now.minute
second = now.second
# Set hours
segment.writeDigit(0, int(hour / 10)) # Tens
segment.writeDigit(1, hour % 10) # Ones
# Set minutes
segment.writeDigit(3, int(minute / 10)) # Tens
segment.writeDigit(4, minute % 10) # Ones
# Toggle colon
segment.setColon(second % 2) # Toggle colon at 1Hz
# Wait one second
示例14: __init__
def __init__(self, address = 0x70, debug=False):
""" Constructor. """
if (debug):
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
self.disp = LEDBackpack(address=address, debug=debug)
示例15: __init__
def __init__(self, address=0x70, bus=Adafruit_I2C.getPiI2CBusNumber(), debug=False):
if (debug):
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
self.disp = LEDBackpack(address=address, bus=bus, debug=debug)