def lcd_display():
    """Write display buffer to physical display."""
    # Reset to position zero
    lcd_command(PCD8544_SETYADDR)
    lcd_command(PCD8544_SETXADDR)
    # Write the buffer
    GPIO.output(DC, GPIO.HIGH)
    for x in range(6):
        SPI.write(lcd_buffer[x * 84:x * 84 + 84])
	def display( self ):
		"""Write display buffer to physical display."""
		# Reset to position zero
		self.command( PCD8544_SETYADDR )
		self.command( PCD8544_SETXADDR )
		# Write the buffer
		GPIO.output( self._dc, GPIO.HIGH )
		for x in range( 6 ):
			_rslt = SPI.write( self._buffer[ x * 84 : x * 84 + 84 ] )
	def __init__( self, spidev, dc, rst, ledpin, ledbrightness ):
		self._spidev = spidev
		self._dc = dc
		self._rst = rst
		self._ledpin = ledpin
		GPIO.setmode( GPIO.BCM )
		GPIO.setup( self._dc, GPIO.OUT )
		GPIO.setup( self._rst, GPIO.OUT )
		GPIO.setup( self._ledpin, GPIO.OUT )
		# brightness should be between 0.1 and 100
		self._ledbrightness = max( 0.1, min( ledbrightness, 100 ) )
		self._ledpwm = GPIO.PWM( self._ledpin, 100 )
		self._ledpwm.start( self._ledbrightness )
		self._spifd = SPI.open( self._spidev, speed = 4000000 )
		self.extended_command( PCD8544_SETBIAS )
		self._buffer = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFF, 0xFC, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 0xC0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x87, 0x8F, 0x9F, 0x9F, 0xFF, 0xFF, 0xFF, 0xC1, 0xC0, 0xE0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC, 0xFC, 0xFE, 0xFE, 0xFE, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF1, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x0F, 0x0F, 0x87, 0xE7, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0x3F, 0xF9, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x7E, 0x3F, 0x3F, 0x0F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xE0, 0xF1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x1F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x1F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]
def main(args):

    # setup
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(DC, GPIO.OUT)
    GPIO.setup(RST, GPIO.OUT)
    GPIO.setup(LED, GPIO.OUT)
    GPIO.output(LED, GPIO.HIGH)

    # SPI.open( SPIDEV, mode = SPIMODE, delay = SPIDELAY, bits_per_word = SPIBPW, speed = SPISPEED )
    SPI.open(SPIDEV, speed=4000000)

    # initialize device, set contrast
    lcd_reset()
    lcd_extended_command(PCD8544_SETBIAS | 4)  # set bias
    lcd_set_contrast(LCDCONTRAST)

    # Clear display
    lcd_clear()
    lcd_display()

    # Create blank image for drawing
    # Make sure to create new image with mode '1' for 1-bit color.
    image = Image.new('1', (LCDWIDTH, LCDHEIGHT))

    # Get drawing object to draw on image.
    draw = ImageDraw.Draw(image)

    # Draw a white filled box to clear the image.
    draw.rectangle((0, 0, LCDWIDTH - 1, LCDHEIGHT - 1), outline=1, fill=1)

    # Draw some shapes.
    draw.ellipse((2, 2, 22, 22), outline=0, fill=1)
    draw.rectangle((24, 2, 44, 22), outline=0, fill=1)
    draw.polygon([(46, 22), (56, 2), (66, 22)], outline=0, fill=1)
    draw.line((68, 22, 81, 2), fill=0)
    draw.line((68, 2, 81, 22), fill=0)

    # Load default font.
    font = ImageFont.load_default()

    # Alternatively load a TTF font.
    # some nice fonts to try: http://www.dafont.com/bitmap.php
    # font = ImageFont.truetype( 'Minecraftia.ttf', 8 )

    # Write some text.
    draw.text((8, 30), 'Hello World!', 0, font=font)

    # Display image
    lcd_image(image)
    lcd_display()

    time.sleep(10)

    lcd_clear()
    lcd_display()

    while True:
        draw.ellipse((18, 0, 65, 47), outline=0, fill=0)

        clk_hr = time.localtime().tm_hour
        if clk_hr > 12:
            clk_hr -= 12

        clk_min = time.localtime().tm_min

        center_x = 42
        center_y = 24

        hr_end_x = 10 * math.cos(
            math.radians(clk_hr * 5 * 6) - math.radians(90)) + center_x
        hr_end_y = 10 * math.sin(
            math.radians(clk_hr * 5 * 6) - math.radians(90)) + center_y

        min_end_x = 15 * math.cos(
            math.radians(clk_min * 6) - math.radians(90)) + center_x
        min_end_y = 15 * math.sin(
            math.radians(clk_min * 6) - math.radians(90)) + center_y

        draw.line((center_x, center_y, hr_end_x, hr_end_y), 1)
        draw.line((center_x, center_y, min_end_x, min_end_y), 1)

        lcd_image(image)
        lcd_display()

        time.sleep(60)

    GPIO.cleanup()
    SPI.close()
    return 0
def lcd_command(c):
    """Send command byte to display """
    # DC pin low signals command byte.
    GPIO.output(DC, GPIO.LOW)
    SPI.write([c])
Exemple #6
0
def main(args):

    # setup
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(DC, GPIO.OUT)
    GPIO.setup(RST, GPIO.OUT)
    GPIO.setup(LED, GPIO.OUT)
    # GPIO.output( LED, GPIO.HIGH )

    # SPI.open( SPIDEV, mode = SPIMODE, delay = SPIDELAY, bits_per_word = SPIBPW, speed = SPISPEED )
    SPI.open(SPIDEV, speed=4000000)

    # initialize device, set contrast
    lcd_reset()
    lcd_extended_command(PCD8544_SETBIAS | 4)  # set bias
    lcd_set_contrast(LCDCONTRAST)

    # Clear display
    lcd_clear()
    lcd_display()

    # Create blank image for drawing
    # Make sure to create new image with mode '1' for 1-bit color.
    image = Image.new('1', (LCDWIDTH, LCDHEIGHT))

    # Get drawing object to draw on image.
    draw = ImageDraw.Draw(image)

    draw.rectangle((0, 0, LCDWIDTH - 1, LCDHEIGHT - 1), outline=1, fill=1)

    while True:
        draw.ellipse((18, 0, 65, 47), outline=0, fill=0)

        clk_hr = time.localtime().tm_hour
        if clk_hr > 12:
            clk_hr -= 12

        clk_min = time.localtime().tm_min

        center_x = 42
        center_y = 24

        hr_end_x = 10 * math.cos(
            math.radians(clk_hr * 5 * 6) - math.radians(90)) + center_x
        hr_end_y = 10 * math.sin(
            math.radians(clk_hr * 5 * 6) - math.radians(90)) + center_y

        min_end_x = 15 * math.cos(
            math.radians(clk_min * 6) - math.radians(90)) + center_x
        min_end_y = 15 * math.sin(
            math.radians(clk_min * 6) - math.radians(90)) + center_y

        draw.line((center_x, center_y, hr_end_x, hr_end_y), 1)
        draw.line((center_x, center_y, min_end_x, min_end_y), 1)

        lcd_image(image)
        lcd_display()

        time.sleep(60)

    GPIO.cleanup()
    SPI.close()
    return 0
	def command( self, c ):
		"""Send command byte to display """
		# DC pin low signals command byte
		GPIO.output( self._dc, GPIO.LOW )
		_rslt = SPI.write( [ c ] )
	def cleanup( self ):
		GPIO.cleanup()
		_rslt = SPI.close()