Exemple #1
0
def main(i2c):
    # Initialize LED matrix.
    matrix = ht16k33_matrix.Matrix16x8(i2c)

    # Initialize font renderer using a helper function to flip the Y axis
    # when rendering so the origin is in the upper left.
    def matrix_pixel(x, y):
        matrix.pixel(x, DISPLAY_HEIGHT - 1 - y, 1)

    with bitmapfont.BitmapFont(DISPLAY_WIDTH, DISPLAY_HEIGHT,
                               matrix_pixel) as bf:
        # Global state:
        pos = DISPLAY_WIDTH  # X position of the message start.
        message_width = bf.width(MESSAGE)  # Message width in pixels.
        last = utime.ticks_ms()  # Last frame millisecond tick time.
        speed_ms = SPEED / 1000.0  # Scroll speed in pixels/ms.
        # Main loop:
        while True:
            # Compute the time delta in milliseconds since the last frame.
            current = utime.ticks_ms()
            delta_ms = utime.ticks_diff(current, last)
            last = current
            # Compute position using speed and time delta.
            pos -= speed_ms * delta_ms
            if pos < -message_width:
                pos = DISPLAY_WIDTH
            # Clear the matrix and draw the text at the current position.
            matrix.fill(0)
            bf.text(MESSAGE, int(pos), 0)
            # Update the matrix LEDs.
            matrix.show()
            # Sleep a bit to give USB mass storage some processing time (quirk
            # of SAMD21 firmware right now).
            utime.sleep_ms(20)
def main(i2c):
    # Initialize Charlieplex matrix wing.
    matrix = is31fl3731.CharlieWing(i2c)
    matrix.fill(0)
    # Initialize font renderer.
    with bitmapfont.BitmapFont(DISPLAY_WIDTH, DISPLAY_HEIGHT,
                               matrix.pixel) as bf:
        # Global state:
        pos = DISPLAY_WIDTH  # X position of the message start.
        message_width = bf.width(MESSAGE)  # Message width in pixels.
        frame = 0  # Currently displayed frame.
        last = utime.ticks_ms()  # Last frame millisecond tick time.
        speed_ms = SPEED / 1000.0  # Scroll speed in pixels/ms.
        while True:
            # Compute the time delta in milliseconds since the last frame.
            current = utime.ticks_ms()
            delta_ms = utime.ticks_diff(current, last)
            last = current
            # Compute position using speed and time delta.
            pos -= speed_ms * delta_ms
            if pos < -message_width:
                pos = DISPLAY_WIDTH
            # Swap frames to start drawing on a non-visible frame (double buffering).
            frame = (frame + 1) % 2
            matrix.frame(frame, show=False)
            # Clear the frame and draw the text at the current position.
            matrix.fill(0)
            bf.text(MESSAGE, int(pos), 0, INTENSITY)
            # Swap to the new frame on the display.
            matrix.frame(frame)
            # Sleep a bit to give USB mass storage some processing time (quirk
            # of SAMD21 firmware right now).
            utime.sleep_ms(20)
def main():
    # Initialize LED matrix.
    matrix = neopixel.NeoPixel(machine.Pin(DIN_PIN, machine.Pin.OUT),
                               DISPLAY_WIDTH * DISPLAY_HEIGHT)

    # Initialize font renderer using a helper function to
    # calculate the index in the neopixel-array
    def matrix_pixel(x, y, color):
        #matrix[y * DISPLAY_WIDTH + x] = color
        matrix[y * DISPLAY_HEIGHT + x] = color

    with bitmapfont.BitmapFont(DISPLAY_HEIGHT, DISPLAY_WIDTH,
                               matrix_pixel) as bf:
        bf.init()
        # Global state:
        pos = DISPLAY_WIDTH  # X position of the message start.
        message_width = bf.width(MESSAGE)  # Message width in pixels.
        last = utime.ticks_ms()  # Last frame millisecond tick time.
        speed_ms = SPEED / 1000.0  # Scroll speed in pixels/ms.

        # Main loop:
        while True:
            # Compute the time delta in milliseconds since the last frame.
            current = utime.ticks_ms()
            delta_ms = utime.ticks_diff(current, last)
            last = current
            # Compute position using speed and time delta.
            pos -= speed_ms * delta_ms
            if pos < -message_width:
                pos = DISPLAY_WIDTH
            # Clear the matrix and draw the text at the current position.
            matrix.fill((0, 0, 0))
            bf.text(MESSAGE, int(pos), 0,
                    (MAX_BRIGHT, 0, MAX_BRIGHT))  # added color
            # Update the matrix LEDs.
            matrix.write()
            # Sleep a bit to give USB mass storage some processing time (quirk
            # of SAMD21 firmware right now).
            utime.sleep_ms(20)
def main():
    # Initialize NeoPixel 8*8 matrix.
    matrix = neopixel.NeoPixel(machine.Pin(13, machine.Pin.OUT), 64)
    matrix.fill((0, 0, 0))  # PePo changed
    matrix.write()

    # define the pixel function, which has to convert a 2-dimensional
    # X, Y location into a 1-dimensional location in the NeoPixel array...
    def matrix_pixel(x, y, color):
        matrix[y * DISPLAY_HEIGHT + x - 1] = color

    with bitmapfont.BitmapFont(DISPLAY_WIDTH, DISPLAY_HEIGHT,
                               matrix_pixel) as bf:
        # Global state:
        pos = DISPLAY_WIDTH  # X position of the message start.
        message_width = bf.width(MESSAGE)  # Message width in pixels.
        #print('MESSAGE is {} pixels wide.'.format(message_width)) #PePo added - debugging
        last = utime.ticks_ms()  # Last frame millisecond tick time.
        speed_ms = SPEED / 1000.0  # Scroll speed in pixels/ms. WAS: 1000
        # Main loop:
        while True:
            # Compute the time delta in milliseconds since the last frame.
            current = utime.ticks_ms()
            delta_ms = utime.ticks_diff(current, last)
            last = current
            # Compute position using speed and time delta.
            pos -= speed_ms * delta_ms
            if pos < -message_width:
                pos = DISPLAY_WIDTH
            # Clear the matrix and draw the text at the current position.
            matrix.fill((0, 0, 0))  # PePo changed
            utime.sleep_ms(20)  #PePo added - not much improvement
            bf.text(MESSAGE, int(pos), 0,
                    (INTENSITY, 0, 0))  #PePo changed: added color
            # Update the matrix.
            matrix.write()  #PePo changed was: matrix.show()
            # Sleep a bit to give USB mass storage some processing time (quirk
            # of SAMD21 firmware right now).
            utime.sleep_ms(20)
import board
import busio
from adafruit_ht16k33 import matrix
import bitmapfont
import time

i2c = busio.I2C(board.SCL, board.SDA)
mx = matrix.Matrix8x8(i2c, auto_write=False)
bf = bitmapfont.BitmapFont(8, 8, mx.pixel)

mx.fill(0)
mx.show()
bf.init()

while True:
    for i in range(15, -30, -1):
        mx.fill(0)
        bf.text('IKEA', i, 0, 100)
        mx.show()
        time.sleep(0.025)
Exemple #6
0

def draw_in_Matrix(x, y, matrix, color=(255, 0, 0)):
    matrix[y][x] = color
    return matrix


# ++++ Debug stuff and test display +++++++++++++++++++++++++++++++++++++++
def display_image(image):
    plt.imshow(image)
    plt.show()
    #alternativ einfach .show von pil benutzen


# ==== Main code ==========================================================
resolutuion = 16

im = pil.Image.open('img/fox.jpg')
nim = to_pix(im, resolutuion)
#displayImage(nim)

matrix = new_canvas(resolutuion)
with bitmapfont.BitmapFont(resolutuion, resolutuion, draw_in_Matrix) as bf:
    bf.text('hallo Welt', 2, 0, matrix, (94, 94, 2))

#drawLine(matrix, (8,8), (8, 13), (255, 50, 87) )
#drawCircle(matrix, (8,8), 6, (32, 64, 128))
display_image(matrix)

# =============
exit(0)
# OLED helper: blank oled screen
def eraseOled():
    oled.fill(0)
    oled.show()


# OLED helper: specify display_pixel function including oled.show()
def display_pixel(x, y, color):
    oled.pixel(x, y, color)
    oled.show()


# generate bitmap font from font5x8.bin
import bitmapfont
# 128 and 64 are the OLED dimensions!
bf = bitmapfont.BitmapFont(_DISPLAY_WIDTH, _DISPLAY_HEIGHT, display_pixel)
bf.init()

# distance value
dist = 0


# main program:
# 1. measure distance
# 2. show on OLED
# 3. dump on serial to other systems
def run():
    while True:
        eraseOled()
        # Get reading from sensor
        #PePo TODO: dist = hc.distance_in_cm()
Exemple #8
0
    def __setitem__(self, coords, color):
        self.pixel(coords[0], coords[1], color)

    def text(self, str, x, y, color):
        if self.type == 'i2c':
            font.text(str, x, y, color)
        elif self.type == 'spi':
            _matrix.text(str, x, y, color)


try:
    i2c = busio.I2C(board.SCL, board.SDA)
    from adafruit_ht16k33.matrix import Matrix8x8
    import bitmapfont
    _matrix = Matrix8x8(i2c, auto_write=False)
    font = bitmapfont.BitmapFont(8, 8, _matrix.pixel)
    font.init()
    type = 'i2c'
except:
    from adafruit_max7219.matrices import Matrix8x8
    cs = digitalio.DigitalInOut(board.D2)
    spi = busio.SPI(
        board.SCK,
        MOSI=board.MOSI,
    )
    _matrix = Matrix8x8(spi, cs)
    _matrix.brightness(9)
    type = 'spi'

matrix = Matrix(type)
joystick = Joystick(board)
# 2016-1219 draw text on neopixel matrix
# https://learn.adafruit.com/micropython-displays-drawing-text/software

import neopixel
import machine

matrix = neopixel.NeoPixel(machine.Pin(13, machine.Pin.OUT), 64)


# define the pixel function, which has to convert a 2-dimensional
# X, Y location into a 1-dimensional location in the NeoPixel array...
def matrix_pixel(x, y, color):
    matrix[y * 8 + x] = color


# Finally create the font class and pass it the pixel function created above...
import bitmapfont
bf = bitmapfont.BitmapFont(8, 8, matrix_pixel)
bf.init()

# Then draw some text!
# tuple-color is passed to the pixel function
bf.text('A', 0, 0, (64, 0, 64))
# Peter: I must write the text-buffer to the neopixel matrix!
matrix.write()

width = bf.width('A')
print('A is {} pixels wide.'.format(width))
Exemple #10
0
from adafruit_rgb_display import ili9341, color565
import bitmapfont



spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# For the Metro
cs = digitalio.DigitalInOut(board.D10)
dc = digitalio.DigitalInOut(board.D9)


display = ili9341.ILI9341(spi, cs=cs, dc=dc, width=320, height=240)
display.write(0x36, b'\x3E')

bf = bitmapfont.BitmapFont(320, 240, display.pixel)  # (240, 320, display.pixel)
bf.init()
 
led = simpleio.DigitalOut(board.D13)
GoButton = DigitalInOut(board.D4)  # pin 4 gets 3.3v to start the party.
GoButton.direction = Direction.INPUT
GoButton.pull = Pull.UP
  
def Rounder(IntInput, MaxNum):
    if (IntInput > MaxNum):
        # print("number over " + (str(MaxNum)) + "! Lowered " + (str(IntInput))) 
        IntInput /= 2
        IntInput = int(round(IntInput))
        # print(" to:" + (str(IntInput)))
        # print("")
    return(IntInput)
Exemple #11
0
from micropython import const
import machine
import myssd1306 as ssd1306  #includes draw_bitmap
#import ssd1306  #excludes draw_bitmap

# OLED dimensions
_DISPLAY_WIDTH = const(128)  # Width of display in pixels.
_DISPLAY_HEIGHT = const(64)  # LoLin-ESP32-OLED height of display.

# generate OLED object
i2c = machine.I2C(scl=machine.Pin(4), sda=machine.Pin(5))
#test: i2c.scan()
oled = ssd1306.SSD1306_I2C(128, 64, i2c)


# helper: specify display_pixel function including oled.show()
def display_pixel(x, y, color):
    oled.pixel(x, y, color)
    oled.show()


# generate bitmap font from font5x8.bin
import bitmapfont
# 128 and 64 are the OLED dimensions!
bf = bitmapfont.BitmapFont(128, 64, display_pixel)
bf.init()

# text on screen with font5*8
bf.text('Dat is een hele kluif!!', 0, 30, 1)
Exemple #12
0
# for console output
if debug:
    print('\nTemperature: {} degrees C'.format(sensor.temperature)) 
    print('Pressure: {}hPa'.format(sensor.pressure))
    print('Altitude: {} meters'.format(sensor.altitude))
    gc.collect()
    ### OLED bounds - bottom left/right, top left/right
    oled.pixel(0, 31, 100)
    oled.pixel(127, 31, 100)
    oled.pixel(0, 0, 100)
    oled.pixel(127, 0, 100)
    gc.collect()
    # free mem
    print("\nfree mem:", gc.mem_free())

bf = bitmapfont.BitmapFont(128, 32, oled.pixel)
bf.init()

def welcome():
    oled.fill(0)
    bf.text("   - MicroVario - ", 0, 0, 100)
    bf.text("version 0.1", 0, 12, 100)
    bf.text("bmosley - 2018", 0, 22, 100)
    oled.show()
    # Startup tune
    buzzer.duty_cycle = DUTY_ON

    for i in range(len(TONE_FREQ)):
        buzzer.frequency = TONE_FREQ[i]
        time.sleep(.1)