当前位置: 首页>>代码示例>>Python>>正文


Python LEDBackpack.clear方法代码示例

本文整理汇总了Python中Adafruit_LEDBackpack.LEDBackpack.clear方法的典型用法代码示例。如果您正苦于以下问题:Python LEDBackpack.clear方法的具体用法?Python LEDBackpack.clear怎么用?Python LEDBackpack.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Adafruit_LEDBackpack.LEDBackpack的用法示例。


在下文中一共展示了LEDBackpack.clear方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: table

# 需要导入模块: from Adafruit_LEDBackpack import LEDBackpack [as 别名]
# 或者: from Adafruit_LEDBackpack.LEDBackpack import clear [as 别名]
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 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)

  def clear(self , position = 99 , update=True):
    'Clears display'
    if position == 99: self.disp.clear(update)
    else: self.disp.setBufferRow(position , 0)

  def getBuffer(self):
    'Returns copy of display buffer'
    return self.disp.getBuffer()
  
  def setNumber(value):
    if value < 0: self.setColon(True)
    else: self.setColon(False)
    self.writeDigit(0 , (abs(value) / 1000)%10)
    self.writeDigit(1 , (abs(value) / 100)%10)
    self.writeDigit(3 , (abs(value) / 10)%10)
    self.writeDigit(4 , abs(value) % 10)

  def setLetter(value):
    if not 9 < value < 16: return
    self.clear()
    self.writeDigit(4 , value)
开发者ID:flyinactor91,项目名称:Adafruit-Raspberry-Pi-Python-Code,代码行数:62,代码来源:Adafruit_7Segment.py

示例2: ColorEightByEight

# 需要导入模块: from Adafruit_LEDBackpack import LEDBackpack [as 别名]
# 或者: from Adafruit_LEDBackpack.LEDBackpack import clear [as 别名]
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()
开发者ID:DustinHendrickson,项目名称:LED_Matrix,代码行数:51,代码来源:Adafruit_8x8.py

示例3: __init__

# 需要导入模块: from Adafruit_LEDBackpack import LEDBackpack [as 别名]
# 或者: from Adafruit_LEDBackpack.LEDBackpack import clear [as 别名]
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 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()

  def setBrightness(self, brightness):
    "Sets the brightness level from 0..15"
    self.disp.setBrightness(brightness)
开发者ID:andyhull,项目名称:Adafruit-Raspberry-Pi-Python-Code,代码行数:44,代码来源:Adafruit_8x8.py

示例4: __init__

# 需要导入模块: from Adafruit_LEDBackpack import LEDBackpack [as 别名]
# 或者: from Adafruit_LEDBackpack.LEDBackpack import clear [as 别名]
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 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()
开发者ID:2RJ,项目名称:Adafruit-Raspberry-Pi-Python-Code-1,代码行数:40,代码来源:Adafruit_8x8.py

示例5: int

# 需要导入模块: from Adafruit_LEDBackpack import LEDBackpack [as 别名]
# 或者: from Adafruit_LEDBackpack.LEDBackpack import clear [as 别名]
  if timer_state == RUN:
    run_time = now - timer_start
  else:
    # Toggle colon
    segment.setColon(now.second % 2)              # Toggle colon at 1Hz

  minute = run_time.seconds / 60
  min_1 = int(minute / 10)
  min_2 = minute % 10
  second = run_time.seconds % 60
  sec_1 = int(second / 10)
  sec_2 = second % 10

  
  backpack.clear()
  # Set minutes
  if min_1 > 0:
    segment.writeDigit(0, min_1)     # Tens
  if min_1 + min_2 > 0:
    segment.writeDigit(1, min_2)     # Ones
  # Set minutes
  if min_1 + min_2 + sec_1 > 0:
    segment.writeDigit(3, sec_1)     # Tens

  segment.writeDigit(4, sec_2)       # Ones

  if(GPIO.input(BUTTON_GPIO) == 1):
    hold_time = hold_time + 1
  else:
    hold_time = 0
开发者ID:johngorosz,项目名称:tsp,代码行数:32,代码来源:tsp_timer.py

示例6: __init__

# 需要导入模块: from Adafruit_LEDBackpack import LEDBackpack [as 别名]
# 或者: from Adafruit_LEDBackpack.LEDBackpack import clear [as 别名]
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)

    # ===========================================================================
    #  A single row operations
    # ===========================================================================

    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, self.wrapValue(value))

    def writeMatrix(self, mx, color=1):
        "Sets a 8x8 matrix"
        row = 0
        for value in mx:
            if row > 7:
                return
            self.disp.setBufferRow(row, self.wrapValue(value), False)
            row += 1
        self.disp.writeDisplay()

    def wrapValue(self, value):
        "A function to mock 8x8 LED bug (offset and flip)"
        valueHI = value & 0xFF00
        valueLO = value & 0x00FF
        valueLO = ((valueLO << 1) & 0xFF) | (valueLO >> 7)
        flip = 0x00
        for i in range(8):
            flip = flip | ((2 ** (7 - i)) if (valueLO & 2 ** i) else 0)
        valueLO = flip & 0x00FF
        return valueHI | valueLO

    # ===========================================================================
    #  A single pixel operations
    # ===========================================================================

    def setPixel(self, x, y):
        "Sets a single pixel"
        if (x > 7) | (y > 7):
            return
        # Set the appropriate pixel
        value = 2 ** x
        buffer = self.disp.getBuffer()
        self.disp.setBufferRow(y, buffer[y] | self.wrapValue(value))

    def clearPixel(self, x, y):
        "Sets a single pixel"
        if (x > 7) | (y > 7):
            return
            # Set the appropriate pixel
        value = ~(2 ** x) & 0xFF
        buffer = self.disp.getBuffer()
        self.disp.setBufferRow(y, buffer[y] & self.wrapValue(value))

    def switchPixel(self, x, y):
        "Sets a single pixel"
        if (x > 7) | (y > 7):
            return
            # Set the appropriate pixel
        value = 2 ** x
        buffer = self.disp.getBuffer()
        self.disp.setBufferRow(y, buffer[y] ^ self.wrapValue(value))

    # ===========================================================================
    #
    # ===========================================================================

    def clear(self):
        "Clears the entire display"
        self.disp.clear()
开发者ID:roboberry,项目名称:Adafruit-Raspberry-Pi-Python-Code,代码行数:81,代码来源:Adafruit_8x8_Mono_0.8in.py


注:本文中的Adafruit_LEDBackpack.LEDBackpack.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。