一区二区三区三上|欧美在线视频五区|国产午夜无码在线观看视频|亚洲国产裸体网站|无码成年人影视|亚洲AV亚洲AV|成人开心激情五月|欧美性爱内射视频|超碰人人干人人上|一区二区无码三区亚洲人区久久精品

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫(xiě)文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

如何使用Adafruit的CircuitPython創(chuàng)建動(dòng)畫(huà)精靈

454398 ? 來(lái)源:網(wǎng)絡(luò)整理 ? 作者:網(wǎng)絡(luò)整理 ? 2019-12-02 09:16 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

概述

馬里奧云與烤面包機(jī)

在此項(xiàng)目中,我們正在制作復(fù)古風(fēng)格的可穿戴設(shè)備!

吊墜具有IPS顯示屏和動(dòng)畫(huà)圖形。它使用Adafruit的CircuitPython創(chuàng)建動(dòng)畫(huà)精靈,看起來(lái)像是在飛行的烤面包機(jī)和滾動(dòng)的云。

我們最初是在Pro Trinket項(xiàng)目中完成這兩個(gè)任務(wù)的,分別是用于烤面包機(jī)的單色OLED和用于云的彩色OLED。為了跟上現(xiàn)代和新的高可見(jiàn)度IPS顯示屏的需要,我們?cè)谶@里將兩個(gè)項(xiàng)目都升級(jí)為使用CircuitPython代替Arduino,以簡(jiǎn)化自定義。顯示屏看起來(lái)也好很多,但是價(jià)格和構(gòu)造都差不多!

3D打印復(fù)古吊墜

使用CircuitPython,您可以使用DisplayIO庫(kù)生成自定義圖形和界面。

您可以使用位圖圖像創(chuàng)建子圖形表和調(diào)色板以生成彩色像素。

該項(xiàng)目中的代碼隨機(jī)生成可在屏幕上連續(xù)滾動(dòng)的飛行烤面包機(jī)。我們認(rèn)為這是一個(gè)很好的例子,讓人們開(kāi)始使用DisplayIO和CircuitPython。

我們制作了兩個(gè)版本,每個(gè)顯示器一個(gè)版本,因此您可以使用1.3英寸或1.54英寸IPS顯示器。

換出圖形并修改代碼以制作自己的動(dòng)畫(huà)也很容易。

零件

選擇您想要的顯示尺寸:

帶MicroSD的Adafruit 1.3“ 240x240廣角TFT LCD顯示屏

Adafruit 1.54“ 240x240廣角TFT LCD顯示屏使用MicroSD

然后添加以下內(nèi)容:

Adafruit ItsyBitsy M4 Express,具有ATSAMD51

Adafruit LiIon/LiPoly背包附加件(用于Pro Trinket/ItsyBitsy)

對(duì)面包板友好SPDT滑動(dòng)開(kāi)關(guān)

鋰離子聚合物電池-3.7v 150mAh

帶MicroSD的Adafruit 1.3“ 240x240廣角TFT LCD顯示屏

產(chǎn)品ID:4313

我們一直在尋找這樣的顯示器-它的對(duì)角線很小,只有1.3英寸,但具有260 ppi的高密度,240x240像素的顯示器。 。.

缺貨

缺貨

帶MicroSD的Adafruit 1.54“ 240x240廣角TFT LCD顯示屏

產(chǎn)品ID:3787

我們一直在尋找這樣的顯示器g時(shí)間-它只有1.5英寸的對(duì)角線,但具有220 ppi的高密度,240x240像素的顯示屏以及全視角。它。..

缺貨

缺貨

具有ATSAMD51的Adafruit ItsyBitsy M4 Express

產(chǎn)品ID:3800

比羽毛小但比小飾品大的東西?這是一款具有Microchip ATSAMD51的Adafruit ItsyBitsy M4 Express!小,。..

$ 14.95

進(jìn)貨

添加到購(gòu)物車

Adafruit LiIon/LiPoly背包附件(適用于Pro Trinket/ItsyBitsy)

產(chǎn)品ID:2124

如果您有ItsyBitsy或Pro Trinket,您可能知道它是便攜式項(xiàng)目的理想選擇。這款LiPoly背包非常容易做到!代替接線2 。..

$ 4.95

進(jìn)貨

添加到購(gòu)物車

適用于面包板的SPDT滑動(dòng)開(kāi)關(guān)

產(chǎn)品ID:805

這些漂亮的開(kāi)關(guān)非常適合與面包板和穿孔板項(xiàng)目一起使用。它們的間距為0.1英寸,可以很好地插入無(wú)焊面包板中。它們易于切換。..

$ 0.95

現(xiàn)貨

添加到購(gòu)物車

鋰離子聚合物電池-3.7v 150mAh

產(chǎn)品ID:1317

鋰離子聚合物電池(也稱為“ lipo”或“ lipoly”)電池很薄,輕巧而功能強(qiáng)大;完全充電后的輸出范圍為4.2V至3.7V。這款電池。..

$ 5.95

IN STOCK

添加到購(gòu)物車

硅樹(shù)脂套絞線帶狀電纜-10線長(zhǎng)1米

產(chǎn)品ID:3890

對(duì)于那些喜歡使用我們的有機(jī)硅包覆電線的人,但始終尋找他們的接線游戲?,F(xiàn)在我們有硅膠蓋帶狀電纜!這些可能看起來(lái)。..

$ 3.95

庫(kù)存中

添加到購(gòu)物車

電路圖

CircuitDiagram

下圖為組件的布線提供了直觀的參考。此圖是使用Fritzing軟件創(chuàng)建的。

用于Fritzing的Adafruit庫(kù)

使用Adafruit的Fritzing零件庫(kù)為您的項(xiàng)目創(chuàng)建電路圖。下載庫(kù)或僅抓取各個(gè)部分。從GitHub Adafruit Fritzing部件獲取庫(kù)和部件。

circuit_diagram.fzz

ItsyBItsy M4到Lipo背包

BAT 從Lipo背包上的ItsyBitsy M4到 BAT

G 從Lipo背包上的ItsyBitsy M4到 G

USB ,從Lisy背包上的ItsyBitsy M4到 5V

顯示

VIN 從顯示更改為 Vhi (從顯示至 G)

GND (從顯示)到ItyBItsy M4上的 SCK

SI 》從顯示到ItsyBItsy M4上的 MO

D/C 從顯示到ItsyBItsy M4上的 7

切換

從切換到Lipo背包

從切換到Lipo背包的左/右

電源

150mAh的鋰電池連接到Lipo背包上的2針JST端口??梢酝ㄟ^(guò)ItsyBitsy M4上的microUSB端口為電池充電。

軟件

使用CircuitPython設(shè)置ItsyBitsy M4

我們需要進(jìn)行板卡設(shè)置,以便我們可以運(yùn)行CircuitPython代碼。讓我們逐步完成這些步驟,以將最新版本的CircuitPython安裝到板上。

Mu Python編輯器

Mu是一個(gè)簡(jiǎn)單的Python編輯器,可與Adafruit CircuitPython硬件一起使用。它是用Python編寫(xiě)的,可在Windows,MacOS,Linux和Raspberry Pi上運(yùn)行。串行控制臺(tái)是內(nèi)置的,因此您可以立即從板子的串行輸出中獲得反饋!雖然您可以在代碼中使用任何文本編輯器,但Mu使其超級(jí)簡(jiǎn)單。

安裝和使用Mu編輯器

安裝或升級(jí)CircuitPython

您應(yīng)確保ItsyBitsy M4上具有CircuitPython 4.0或更高版本。使用已知的優(yōu)質(zhì)數(shù)據(jù)+電源線(而不是USB電源包隨附的俗氣的USB電纜,它們僅是電源)插入板子。您應(yīng)該會(huì)看到一個(gè)彈出的新閃存驅(qū)動(dòng)器。

如果驅(qū)動(dòng)器為 CIRCUITPY ,請(qǐng)打開(kāi) boot_out.txt 文件以確保版本號(hào)為4.0或更高版本。

下載:文件

復(fù)制代碼

Adafruit CircuitPython 5.0.0-alpha.4 on 2019-09-15; Adafruit ItsyBitsy M4 Express with samd51j19 Adafruit CircuitPython 5.0.0-alpha.4 on 2019-09-15; Adafruit ItsyBitsy M4 Express with samd51j19

如果版本小于4,或者-您僅獲得名為 ITSYM4BOOT 的驅(qū)動(dòng)器,請(qǐng)按照以下步驟操作要更新電路板CircuitPython軟件,請(qǐng)執(zhí)行以下操作:

通過(guò)下面的綠色按鈕下載ItsyBitsy M4的CircuitPython UF2。

通過(guò)USB將ItsyBitsy M4連接到計(jì)算機(jī),然后按Reset(重置)按鈕。

將CircuitPython UF2 拖放到 ITSYM4BOOT 驅(qū)動(dòng)器上-該驅(qū)動(dòng)器將消失,并出現(xiàn)一個(gè)新的 CIRCUITPY 驅(qū)動(dòng)器應(yīng)該會(huì)出現(xiàn)。

下載itsyBItsy M4的CircuitPython

下載Adafruit CircuitPython庫(kù)捆綁

要運(yùn)行代碼,我們需要下載一些庫(kù)。庫(kù)中包含的代碼有助于我們更輕松地與硬件連接。

下面的綠色按鈕鏈接到一個(gè)文件,其中包含CircuitPython可用的所有庫(kù)。要運(yùn)行該項(xiàng)目的代碼,我們需要下面“必需的庫(kù)”列表中的兩個(gè)庫(kù)。解壓縮庫(kù)捆綁包并搜索庫(kù)。將文件拖放到 CIRCUITPY 驅(qū)動(dòng)器上的名為 lib 的文件夾中(如果該文件夾不在ItsyBitsy M4上,則創(chuàng)建該文件夾)。

下載Circuit Python庫(kù)捆綁包

必需的庫(kù)

adafruit_st7789

adafruit_imageload

有了所有需要的文件后,目錄列表在文件和目錄上看起來(lái)類似于下面。

上傳代碼

該項(xiàng)目提供了兩個(gè)不同的 code.py 草圖。這兩個(gè)程序都可以在任何一個(gè)顯示器上使用。

單擊下面的下載鏈接以直接從GitHub獲取主要代碼。將文件重命名為 code.py 并將其拖放到 CIRCUITPY 主(根)目錄中。上載所有文件(包括庫(kù))后,該代碼即可正常運(yùn)行。

使用任何文本編輯器或常用的IDE修改代碼。我們建議如上所述使用Mu。

上載位圖

下載以下位圖圖像并將其保存到 CIRCUITPY 驅(qū)動(dòng)器的根目錄。

tilesheet-2x.bmp 用于Mario Clouds代碼。

spritesheet-2x.bmp 用于Flying Toasters代碼。

位圖圖像的命名不同,因此兩個(gè)文件都可以駐留在 CIRCUITPY 驅(qū)動(dòng)器中。

滾動(dòng)云

下載:項(xiàng)目Zip 或 code.py | 在Github上查看

復(fù)制代碼

“”“

Continuously scroll randomly generated Mario style clouds.

Designed fr an ItsyBitsy M4 Express and a 1.3” 240x240 TFT

Adafruit invests time and resources providing this open source code.

Please support Adafruit and open source hardware by purchasing

products from Adafruit!

Written by Dave Astels for Adafruit Industries

Copyright (c) 2019 Adafruit Industries

Licensed under the MIT license.

All text above must be included in any redistribution.

“”“

import time

from random import seed, randint

import board

import displayio

from adafruit_st7789 import ST7789

import adafruit_imageload

# Sprite cell values

EMPTY = 0

LEFT = 1

MIDDLE = 2

RIGHT = 3

# These constants determine what happens when tiles are shifted.

# if randint(1, 10) 》 the value, the thing happens

# The chance a new cloud will enter

CHANCE_OF_NEW_CLOUD = 4

# The chance an existing cloud gets extended

CHANCE_OF_EXTENDING_A_CLOUD = 5

# Global variables

display = None

tilegrid = None

seed(int(time.monotonic()))

def make_display():

”“”Set up the display support.

Return the Display object.

“”“

spi = board.SPI()

while not spi.try_lock():

pass

spi.configure(baudrate=24000000) # Configure SPI for 24MHz

spi.unlock()

displayio.release_displays()

display_bus = displayio.FourWire(spi, command=board.D7, chip_select=board.D10, reset=board.D9)

return ST7789(display_bus, width=240, height=240, rowstart=80, auto_refresh=True)

def make_tilegrid():

”“”Construct and return the tilegrid.“”“

group = displayio.Group(max_size=10)

sprite_sheet, palette = adafruit_imageload.load(”/tilesheet-2x.bmp“,

bitmap=displayio.Bitmap,

palette=displayio.Palette)

grid = displayio.TileGrid(sprite_sheet, pixel_shader=palette,

width=9, height=5,

tile_height=48, tile_width=32,

default_tile=EMPTY)

group.append(grid)

display.show(group)

return grid

def evaluate_position(row, col):

”“”Return how long of a cloud is placable at the given location.

:param row: the tile row (0-4)

:param col: the tile column (0-8)

“”“

if tilegrid[col, row] != EMPTY or tilegrid[col + 1, row] != EMPTY:

return 0

end_col = col + 1

while end_col 《 9 and tilegrid[end_col, row] == EMPTY:

end_col += 1

return min([4, end_col - col])

def seed_clouds(number_of_clouds):

”“”Create the initial clouds so it doesn‘t start empty“”“

for _ in range(number_of_clouds):

while True:

row = randint(0, 4)

col = randint(0, 7)

cloud_length = evaluate_position(row, col)

if cloud_length 》 0:

break

l = randint(1, cloud_length)

tilegrid[col, row] = LEFT

for _ in range(l - 2):

col += 1

tilegrid[col, row] = MIDDLE

tilegrid[col + 1, row] = RIGHT

def slide_tiles():

”“”Move the tilegrid to the left, one pixel at a time, a full time width“”“

for _ in range(32):

tilegrid.x -= 1

display.refresh(target_frames_per_second=60)

def shift_tiles():

”“”Move tiles one spot to the left, and reset the tilegrid’s position“”“

for row in range(5):

for col in range(8):

tilegrid[col, row] = tilegrid[col + 1, row]

tilegrid[8, row] = EMPTY

tilegrid.x = 0

def extend_clouds():

”“”Extend any clouds on the right edge, either finishing them with a right

end or continuing them with a middle piece

“”“

for row in range(5):

if tilegrid[7, row] == LEFT or tilegrid[7, row] == MIDDLE:

if randint(1, 10) 》 CHANCE_OF_EXTENDING_A_CLOUD:

tilegrid[8, row] = MIDDLE

else:

tilegrid[8, row] = RIGHT

def add_cloud():

”“”Maybe add a new cloud on the right at a randon open row“”“

if randint(1, 10) 》 CHANCE_OF_NEW_CLOUD:

count = 0

while True:

count += 1

if count == 50:

return

row = randint(0, 4)

if tilegrid[7, row] == EMPTY and tilegrid[8, row] == EMPTY:

break

tilegrid[8, row] = LEFT

display = make_display()

tilegrid = make_tilegrid()

seed_clouds(5)

while True:

slide_tiles()

shift_tiles()

extend_clouds()

add_cloud()

”“”

Continuously scroll randomly generated Mario style clouds.

Designed fr an ItsyBitsy M4 Express and a 1.3“ 240x240 TFT

Adafruit invests time and resources providing this open source code.

Please support Adafruit and open source hardware by purchasing

products from Adafruit!

Written by Dave Astels for Adafruit Industries

Copyright (c) 2019 Adafruit Industries

Licensed under the MIT license.

All text above must be included in any redistribution.

”“”

import time

from random import seed, randint

import board

import displayio

from adafruit_st7789 import ST7789

import adafruit_imageload

# Sprite cell values

EMPTY = 0

LEFT = 1

MIDDLE = 2

RIGHT = 3

# These constants determine what happens when tiles are shifted.

# if randint(1, 10) 》 the value, the thing happens

# The chance a new cloud will enter

CHANCE_OF_NEW_CLOUD = 4

# The chance an existing cloud gets extended

CHANCE_OF_EXTENDING_A_CLOUD = 5

# Global variables

display = None

tilegrid = None

seed(int(time.monotonic()))

def make_display():

“”“Set up the display support.

Return the Display object.

”“”

spi = board.SPI()

while not spi.try_lock():

pass

spi.configure(baudrate=24000000) # Configure SPI for 24MHz

spi.unlock()

displayio.release_displays()

display_bus = displayio.FourWire(spi, command=board.D7, chip_select=board.D10, reset=board.D9)

return ST7789(display_bus, width=240, height=240, rowstart=80, auto_refresh=True)

def make_tilegrid():

“”“Construct and return the tilegrid.”“”

group = displayio.Group(max_size=10)

sprite_sheet, palette = adafruit_imageload.load(“/tilesheet-2x.bmp”,

bitmap=displayio.Bitmap,

palette=displayio.Palette)

grid = displayio.TileGrid(sprite_sheet, pixel_shader=palette,

width=9, height=5,

tile_height=48, tile_width=32,

default_tile=EMPTY)

group.append(grid)

display.show(group)

return grid

def evaluate_position(row, col):

“”“Return how long of a cloud is placable at the given location.

:param row: the tile row (0-4)

:param col: the tile column (0-8)

”“”

if tilegrid[col, row] != EMPTY or tilegrid[col + 1, row] != EMPTY:

return 0

end_col = col + 1

while end_col 《 9 and tilegrid[end_col, row] == EMPTY:

end_col += 1

return min([4, end_col - col])

def seed_clouds(number_of_clouds):

“”“Create the initial clouds so it doesn‘t start empty”“”

for _ in range(number_of_clouds):

while True:

row = randint(0, 4)

col = randint(0, 7)

cloud_length = evaluate_position(row, col)

if cloud_length 》 0:

break

l = randint(1, cloud_length)

tilegrid[col, row] = LEFT

for _ in range(l - 2):

col += 1

tilegrid[col, row] = MIDDLE

tilegrid[col + 1, row] = RIGHT

def slide_tiles():

“”“Move the tilegrid to the left, one pixel at a time, a full time width”“”

for _ in range(32):

tilegrid.x -= 1

display.refresh(target_frames_per_second=60)

def shift_tiles():

“”“Move tiles one spot to the left, and reset the tilegrid’s position”“”

for row in range(5):

for col in range(8):

tilegrid[col, row] = tilegrid[col + 1, row]

tilegrid[8, row] = EMPTY

tilegrid.x = 0

def extend_clouds():

“”“Extend any clouds on the right edge, either finishing them with a right

end or continuing them with a middle piece

”“”

for row in range(5):

if tilegrid[7, row] == LEFT or tilegrid[7, row] == MIDDLE:

if randint(1, 10) 》 CHANCE_OF_EXTENDING_A_CLOUD:

tilegrid[8, row] = MIDDLE

else:

tilegrid[8, row] = RIGHT

def add_cloud():

“”“Maybe add a new cloud on the right at a randon open row”“”

if randint(1, 10) 》 CHANCE_OF_NEW_CLOUD:

count = 0

while True:

count += 1

if count == 50:

return

row = randint(0, 4)

if tilegrid[7, row] == EMPTY and tilegrid[8, row] == EMPTY:

break

tilegrid[8, row] = LEFT

display = make_display()

tilegrid = make_tilegrid()

seed_clouds(5)

while True:

slide_tiles()

shift_tiles()

extend_clouds()

add_cloud()

飛行烤面包機(jī)

下載:Project Zip 或 code.py | 在Github上查看

復(fù)制代碼

“”“

Continuously scroll randomly generated After Dark style toasters.

Designed for an ItsyBitsy M4 Express and a 1.3” 240x240 TFT

Adafruit invests time and resources providing this open source code.

Please support Adafruit and open source hardware by purchasing

products from Adafruit!

Written by Dave Astels for Adafruit Industries

Copyright (c) 2019 Adafruit Industries

Licensed under the MIT license.

All text above must be included in any redistribution.

Requires CircuitPython 5.0 or later.

“”“

import time

from random import seed, randint

import board

import displayio

from adafruit_st7789 import ST7789

import adafruit_imageload

# Sprite cell values

EMPTY = 0

CELL_1 = EMPTY + 1

CELL_2 = CELL_1 + 1

CELL_3 = CELL_2 + 1

CELL_4 = CELL_3 + 1

TOAST = CELL_4 + 1

NUMBER_OF_SPRITES = TOAST + 1

# Animation support

FIRST_CELL = CELL_1

LAST_CELL = CELL_4

NUMBER_OF_CELLS = (LAST_CELL - FIRST_CELL) + 1

# A boolean array corresponding to the sprites, True if it‘s part of the animation sequence.

ANIMATED = [_sprite 》= FIRST_CELL and _sprite 《= LAST_CELL for _sprite in range(NUMBER_OF_SPRITES)]

# The chance (out of 10) that toast will enter

CHANCE_OF_NEW_TOAST = 2

# How many sprites to styart with

INITIAL_NUMBER_OF_SPRITES = 4

# Global variables

display = None

tilegrid = None

seed(int(time.monotonic()))

def make_display():

”“”Set up the display support.

Return the Display object.

“”“

spi = board.SPI()

while not spi.try_lock():

pass

spi.configure(baudrate=24000000) # Configure SPI for 24MHz

spi.unlock()

displayio.release_displays()

display_bus = displayio.FourWire(spi, command=board.D7, chip_select=board.D10, reset=board.D9)

return ST7789(display_bus, width=240, height=240, rowstart=80, auto_refresh=True)

def make_tilegrid():

”“”Construct and return the tilegrid.“”“

group = displayio.Group(max_size=10)

sprite_sheet, palette = adafruit_imageload.load(”/spritesheet-2x.bmp“,

bitmap=displayio.Bitmap,

palette=displayio.Palette)

grid = displayio.TileGrid(sprite_sheet, pixel_shader=palette,

width=5, height=5,

tile_height=64, tile_width=64,

x=0, y=-64,

default_tile=EMPTY)

group.append(grid)

display.show(group)

return grid

def random_cell():

return randint(FIRST_CELL, LAST_CELL)

def evaluate_position(row, col):

”“”Return whether how long of aa toaster is placable at the given location.

:param row: the tile row (0-9)

:param col: the tile column (0-9)

“”“

return tilegrid[col, row] == EMPTY

def seed_toasters(number_of_toasters):

”“”Create the initial toasters so it doesn’t start empty“”“

for _ in range(number_of_toasters):

while True:

row = randint(0, 4)

col = randint(0, 4)

if evaluate_position(row, col):

break

tilegrid[col, row] = random_cell()

def next_sprite(sprite):

if ANIMATED[sprite]:

return (((sprite - FIRST_CELL) + 1) % NUMBER_OF_CELLS) + FIRST_CELL

return sprite

def advance_animation():

”“”Cycle through animation cells each time.“”“

for tile_number in range(25):

tilegrid[tile_number] = next_sprite(tilegrid[tile_number])

def slide_tiles():

”“”Move the tilegrid one pixel to the bottom-left.“”“

tilegrid.x -= 1

tilegrid.y += 1

def shift_tiles():

”“”Move tiles one spot to the left, and reset the tilegrid‘s position“”“

for row in range(4, 0, -1):

for col in range(4):

tilegrid[col, row] = tilegrid[col + 1, row - 1]

tilegrid[4, row] = EMPTY

for col in range(5):

tilegrid[col, 0] = EMPTY

tilegrid.x = 0

tilegrid.y = -64

def get_entry_row():

while True:

row = randint(0, 4)

if tilegrid[4, row] == EMPTY and tilegrid[3, row] == EMPTY:

return row

def get_entry_column():

while True:

col = randint(0, 3)

if tilegrid[col, 0] == EMPTY and tilegrid[col, 1] == EMPTY:

return col

def add_toaster_or_toast():

”“”Maybe add a new toaster or toast on the right and/or top at a randon open location“”“

if randint(1, 10) 《= CHANCE_OF_NEW_TOAST:

tile = TOAST

else:

tile = random_cell()

tilegrid[4, get_entry_row()] = tile

if randint(1, 10) 《= CHANCE_OF_NEW_TOAST:

tile = TOAST

else:

tile = random_cell()

tilegrid[get_entry_column(), 0] = tile

display = make_display()

tilegrid = make_tilegrid()

seed_toasters(INITIAL_NUMBER_OF_SPRITES)

display.refresh()

while True:

for _ in range(64):

display.refresh(target_frames_per_second=80)

advance_animation()

slide_tiles()

shift_tiles()

add_toaster_or_toast()

display.refresh(target_frames_per_second=120)

”“”

Continuously scroll randomly generated After Dark style toasters.

Designed for an ItsyBitsy M4 Express and a 1.3“ 240x240 TFT

Adafruit invests time and resources providing this open source code.

Please support Adafruit and open source hardware by purchasing

products from Adafruit!

Written by Dave Astels for Adafruit Industries

Copyright (c) 2019 Adafruit Industries

Licensed under the MIT license.

All text above must be included in any redistribution.

Requires CircuitPython 5.0 or later.

”“”

import time

from random import seed, randint

import board

import displayio

from adafruit_st7789 import ST7789

import adafruit_imageload

# Sprite cell values

EMPTY = 0

CELL_1 = EMPTY + 1

CELL_2 = CELL_1 + 1

CELL_3 = CELL_2 + 1

CELL_4 = CELL_3 + 1

TOAST = CELL_4 + 1

NUMBER_OF_SPRITES = TOAST + 1

# Animation support

FIRST_CELL = CELL_1

LAST_CELL = CELL_4

NUMBER_OF_CELLS = (LAST_CELL - FIRST_CELL) + 1

# A boolean array corresponding to the sprites, True if it’s part of the animation sequence.

ANIMATED = [_sprite 》= FIRST_CELL and _sprite 《= LAST_CELL for _sprite in range(NUMBER_OF_SPRITES)]

# The chance (out of 10) that toast will enter

CHANCE_OF_NEW_TOAST = 2

# How many sprites to styart with

INITIAL_NUMBER_OF_SPRITES = 4

# Global variables

display = None

tilegrid = None

seed(int(time.monotonic()))

def make_display():

“”“Set up the display support.

Return the Display object.

”“”

spi = board.SPI()

while not spi.try_lock():

pass

spi.configure(baudrate=24000000) # Configure SPI for 24MHz

spi.unlock()

displayio.release_displays()

display_bus = displayio.FourWire(spi, command=board.D7, chip_select=board.D10, reset=board.D9)

return ST7789(display_bus, width=240, height=240, rowstart=80, auto_refresh=True)

def make_tilegrid():

“”“Construct and return the tilegrid.”“”

group = displayio.Group(max_size=10)

sprite_sheet, palette = adafruit_imageload.load(“/spritesheet-2x.bmp”,

bitmap=displayio.Bitmap,

palette=displayio.Palette)

grid = displayio.TileGrid(sprite_sheet, pixel_shader=palette,

width=5, height=5,

tile_height=64, tile_width=64,

x=0, y=-64,

default_tile=EMPTY)

group.append(grid)

display.show(group)

return grid

def random_cell():

return randint(FIRST_CELL, LAST_CELL)

def evaluate_position(row, col):

“”“Return whether how long of aa toaster is placable at the given location.

:param row: the tile row (0-9)

:param col: the tile column (0-9)

”“”

return tilegrid[col, row] == EMPTY

def seed_toasters(number_of_toasters):

“”“Create the initial toasters so it doesn‘t start empty”“”

for _ in range(number_of_toasters):

while True:

row = randint(0, 4)

col = randint(0, 4)

if evaluate_position(row, col):

break

tilegrid[col, row] = random_cell()

def next_sprite(sprite):

if ANIMATED[sprite]:

return (((sprite - FIRST_CELL) + 1) % NUMBER_OF_CELLS) + FIRST_CELL

return sprite

def advance_animation():

“”“Cycle through animation cells each time.”“”

for tile_number in range(25):

tilegrid[tile_number] = next_sprite(tilegrid[tile_number])

def slide_tiles():

“”“Move the tilegrid one pixel to the bottom-left.”“”

tilegrid.x -= 1

tilegrid.y += 1

def shift_tiles():

“”“Move tiles one spot to the left, and reset the tilegrid’s position”“”

for row in range(4, 0, -1):

for col in range(4):

tilegrid[col, row] = tilegrid[col + 1, row - 1]

tilegrid[4, row] = EMPTY

for col in range(5):

tilegrid[col, 0] = EMPTY

tilegrid.x = 0

tilegrid.y = -64

def get_entry_row():

while True:

row = randint(0, 4)

if tilegrid[4, row] == EMPTY and tilegrid[3, row] == EMPTY:

return row

def get_entry_column():

while True:

col = randint(0, 3)

if tilegrid[col, 0] == EMPTY and tilegrid[col, 1] == EMPTY:

return col

def add_toaster_or_toast():

“”“Maybe add a new toaster or toast on the right and/or top at a randon open location”“”

if randint(1, 10) 《= CHANCE_OF_NEW_TOAST:

tile = TOAST

else:

tile = random_cell()

tilegrid[4, get_entry_row()] = tile

if randint(1, 10) 《= CHANCE_OF_NEW_TOAST:

tile = TOAST

else:

tile = random_cell()

tilegrid[get_entry_column(), 0] = tile

display = make_display()

tilegrid = make_tilegrid()

seed_toasters(INITIAL_NUMBER_OF_SPRITES)

display.refresh()

while True:

for _ in range(64):

display.refresh(target_frames_per_second=80)

advance_animation()

slide_tiles()

shift_tiles()

add_toaster_or_toast()

display.refresh(target_frames_per_second=120)

仔細(xì)檢查

查看上面列出的目錄,并仔細(xì)檢查是否列出了所有文件以使該項(xiàng)目起作用。如果缺少任何內(nèi)容或在不正確的目錄中,請(qǐng)將它們移到正確的位置。

3D打印

該項(xiàng)目的零件被設(shè)計(jì)為用基于FDM的機(jī)器進(jìn)行3D打印。 STL文件旨在按“原樣”打印。零件需要嚴(yán)格的公差,可能需要調(diào)整切片設(shè)置。請(qǐng)參考下面的建議設(shè)置。

CAD文件

可以將零件進(jìn)一步分成小塊,以適合較小的打印機(jī)建立卷。注意:STEP文件包含在其他3D表面建模程序中,例如Onshape,Solidworks和Rhino。

用于1.3 Display的編輯工況

用于1.5 Display的編輯工況

下載按鈕STL

下載案例STL

設(shè)置

使用這些設(shè)置作為參考。列出的值在Cura切片軟件中使用。

0.2mm層高/0.4mm噴嘴

0.4mm線寬(內(nèi)部和外部寬度)

50mm/s打印速度

10% infill

支持:否

裙子:3

組裝

Tin顯示器連接

我用了第三只幫助手來(lái)穩(wěn)定顯示器。根據(jù)電路圖鍍錫連接。

焊錫絲

我剪斷了導(dǎo)線,使其足夠長(zhǎng),可以到達(dá)ItsyBitsy。硅膠帶狀電纜非常好,因此我們可以將電線束保持在機(jī)箱內(nèi)整潔。

Tin ItsyBitsy

我用了第二對(duì)幫助手將ItsyBitsy固定在顯示屏上方。參照電路圖,并在ItsyBitsy上進(jìn)行連接。

焊接ItsyBitsy以顯示

輕輕地拉開(kāi)每根電線,使每根電線都能到達(dá)ItsyBitsy上的連接。請(qǐng)參考電路圖,并將ItsyBitsy焊接到顯示器上。

Prep Lipo充電器背包

現(xiàn)在,我們可以準(zhǔn)備LiPoly充電器背包。電池輸出線是兩個(gè)0.1“孔,周圍有一個(gè)框,它們是電池輸出線。用一把小刀小心地切開(kāi)它們之間的走線,并將兩根導(dǎo)線焊接到滑動(dòng)開(kāi)關(guān)上。

脂背包,為了更好地安裝機(jī)箱內(nèi)的板,我們可以從底部焊接電線。

將Lipo背包裝到ItsyBitsy

然后用帶狀電纜將lipo背包焊接到ItsyBitsy。絕緣板

我們需要對(duì)板進(jìn)行絕緣,以免它們一次接觸到外殼內(nèi)。我用一條膠帶將ItyBitsy和lipo的底部覆蓋

將面板插入機(jī)箱中

將顯示板插入機(jī)箱中,使帶有連接的一面朝向面板的切口

布置ItsyBitsy,使USB端口與外殼上的USB切口對(duì)齊。

將脂質(zhì)背包布置在JST端口面向滑動(dòng)開(kāi)關(guān)切口的情況下。

將脂電池連接到背包上的JST,并纏繞電池導(dǎo)線,并將導(dǎo)線插入機(jī)箱上滑動(dòng)開(kāi)關(guān)切口的壁下。

按入配合蓋子

對(duì)準(zhǔn)蓋子,使切口適合外殼上的滑動(dòng)開(kāi)關(guān)壁。以一定角度插入蓋子,使電池位于中央,然后將蓋子輕輕按入外殼。

膠水按鈕

測(cè)試外殼上按鈕的布局,然后使用一小撮超級(jí)膠水將其粘附在適當(dāng)?shù)奈恢谩?/p>

裂環(huán)和項(xiàng)鏈

開(kāi)口環(huán)套在蓋子的環(huán)上。然后,項(xiàng)鏈或掛繩可以穿過(guò)開(kāi)口環(huán),準(zhǔn)備戴上!

就可以了!這樣便可以創(chuàng)建自己的復(fù)古風(fēng)格可穿戴設(shè)備!

如果您要共享項(xiàng)目,請(qǐng)查看Adafruit的Show and Tell live流。

所有參與者都將獲得免費(fèi)的乙烯基貼紙。

您還可以檢出Adafruit Discord服務(wù)器,以便與社區(qū)聊天!
責(zé)任編輯:wv

聲明:本文內(nèi)容及配圖由入駐作者撰寫(xiě)或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 顯示屏
    +關(guān)注

    關(guān)注

    28

    文章

    4605

    瀏覽量

    76401
  • microSD
    +關(guān)注

    關(guān)注

    1

    文章

    50

    瀏覽量

    16160
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    輸電線路的“智慧之眼”——觀冰精靈守護(hù)電網(wǎng)安全

    觀冰精靈,又稱覆冰精靈或?qū)Ь€精靈,是一種專門(mén)用于監(jiān)測(cè)和識(shí)別輸電線路覆冰情況的智能識(shí)別監(jiān)測(cè)裝置。它通過(guò)工業(yè)攝像機(jī)采集線路覆冰前后的圖像,利用先進(jìn)的算法比較圖像邊界輪廓,精準(zhǔn)預(yù)測(cè)輸電線路覆冰的厚度,讓運(yùn)維人員及時(shí)了解線路覆冰狀態(tài)。
    的頭像 發(fā)表于 06-09 11:41 ?174次閱讀
    輸電線路的“智慧之眼”——觀冰<b class='flag-5'>精靈</b>守護(hù)電網(wǎng)安全

    用Manim動(dòng)畫(huà)生動(dòng)演示勾股定理

    用Manim這一專業(yè)的數(shù)學(xué)動(dòng)畫(huà)引擎,我們可以將抽象的數(shù)學(xué)概念轉(zhuǎn)化為生動(dòng)的視覺(jué)呈現(xiàn),大幅提升教學(xué)效果。 二,Manim動(dòng)畫(huà)的優(yōu)勢(shì) 1. 動(dòng)態(tài)可視化:通過(guò)動(dòng)畫(huà)展示直角三角形三邊關(guān)系的形成過(guò)程 2. 精準(zhǔn)演示:嚴(yán)格按照數(shù)學(xué)比例構(gòu)建圖形
    的頭像 發(fā)表于 04-27 16:36 ?271次閱讀

    用DeepSeek-R1實(shí)現(xiàn)自動(dòng)生成Manim動(dòng)畫(huà)

    動(dòng)畫(huà),視覺(jué)化呈現(xiàn)抽象的概念與原理。 什么是Manim? ?Manim 是一個(gè)基于 Python 的動(dòng)畫(huà)引擎,專門(mén)用于創(chuàng)建高質(zhì)量的數(shù)學(xué)相關(guān)動(dòng)畫(huà),廣泛應(yīng)用于教育、科普等領(lǐng)域,幫助人們更直觀
    的頭像 發(fā)表于 02-07 12:31 ?3353次閱讀
    用DeepSeek-R1實(shí)現(xiàn)自動(dòng)生成Manim<b class='flag-5'>動(dòng)畫(huà)</b>

    天貓精靈與夸克團(tuán)隊(duì)攜手設(shè)計(jì)AI眼鏡

    近日,阿里巴巴集團(tuán)內(nèi)部的智能互聯(lián)事業(yè)群迎來(lái)了新的管理變革,由總裁吳嘉正式接管這一關(guān)鍵業(yè)務(wù)板塊。作為阿里巴巴面向廣大消費(fèi)者的重要硬件業(yè)務(wù)之一,“天貓精靈”將繼續(xù)保持其獨(dú)立運(yùn)營(yíng)的特色與優(yōu)勢(shì)。 在當(dāng)前快速
    的頭像 發(fā)表于 01-20 10:28 ?1859次閱讀

    帶電安裝導(dǎo)線精靈 助力輸電線路防冰抗災(zāi)

    帶電安裝導(dǎo)線精靈 助力輸電線路防冰抗災(zāi)
    的頭像 發(fā)表于 12-06 16:55 ?358次閱讀

    標(biāo)配即滿配!深視智能精靈系列高速相機(jī)新品上市!

    高速相機(jī)領(lǐng)域新品-精靈系列精靈系列是深視智能高速相機(jī)家族面向高端科研與工業(yè)領(lǐng)域的匠心之作。精靈系列高速相機(jī)以小巧體積、強(qiáng)大性能、豐富內(nèi)存選項(xiàng),滿足不同用戶復(fù)雜場(chǎng)景應(yīng)用需求,為高端科研和工業(yè)領(lǐng)域帶來(lái)
    的頭像 發(fā)表于 10-29 08:08 ?1018次閱讀
    標(biāo)配即滿配!深視智能<b class='flag-5'>精靈</b>系列高速相機(jī)新品上市!

    智慧安全用電產(chǎn)品-用電精靈

    用電精靈是什么? 用電精靈主要功能是針對(duì)用電回路的漏電、溫度、電壓、電流、電能等檢測(cè),漏電、超溫、過(guò)欠壓、過(guò)流保護(hù)。安裝位置:出線回路;不需要控制分合閘。適用于單相、雙火線、三相三線、三相四線中性點(diǎn)
    的頭像 發(fā)表于 10-16 14:37 ?812次閱讀
    智慧安全用電產(chǎn)品-用電<b class='flag-5'>精靈</b>

    導(dǎo)線精靈是什么

    導(dǎo)線精靈,也被稱為觀冰精靈或覆冰精靈,是一種專為輸電線路設(shè)計(jì)的覆冰智能識(shí)別監(jiān)測(cè)裝置,能夠精準(zhǔn)捕捉并識(shí)別線路上的覆冰狀態(tài)。 一、主要功能 覆冰監(jiān)測(cè) :通過(guò)工業(yè)攝像機(jī)采集線路覆冰前后的圖像,利用算法比較
    的頭像 發(fā)表于 10-16 09:45 ?768次閱讀
    導(dǎo)線<b class='flag-5'>精靈</b>是什么

    導(dǎo)線精靈是什么

    導(dǎo)線精靈,也被稱為觀冰精靈或覆冰精靈,是一種專為輸電線路設(shè)計(jì)的覆冰智能識(shí)別監(jiān)測(cè)裝置。以下是對(duì)導(dǎo)線精靈的詳細(xì)介紹:一、主要功能覆冰監(jiān)測(cè):通過(guò)工業(yè)攝像機(jī)采集線路覆冰前后的圖像,利用算法比較
    的頭像 發(fā)表于 10-16 09:24 ?765次閱讀
    導(dǎo)線<b class='flag-5'>精靈</b>是什么

    ESP8266 太空人動(dòng)畫(huà)的 OLED 顯示

    ESP8266 太空人動(dòng)畫(huà)的 OLED 顯示
    的頭像 發(fā)表于 10-08 15:06 ?707次閱讀
    ESP8266 太空人<b class='flag-5'>動(dòng)畫(huà)</b>的 OLED 顯示

    【核桃派ZeroW開(kāi)發(fā)板體驗(yàn)連載】小小氣象站 04 oled測(cè)試

    : sudo pip3 install adafruit-circuitpython-ssd1306 測(cè)試 按上一篇接線的SCL、SDA接在I2C1上面,這樣體現(xiàn)了I2C的一個(gè)特點(diǎn),就是一個(gè)接口可以接
    發(fā)表于 08-11 13:33

    【核桃派ZeroW開(kāi)發(fā)板體驗(yàn)連載】小小氣象站 03 aht10、bmp280測(cè)試

    adafruit-circuitpython-ahtx0 安裝完成后,打開(kāi)遠(yuǎn)程python,新建一個(gè)文件,命名為aht10_test.py,進(jìn)入,寫(xiě)入以下代碼: \'\'\' 實(shí)驗(yàn)名稱:AHT10溫濕度
    發(fā)表于 08-10 10:04

    【xG24 Matter開(kāi)發(fā)套件試用體驗(yàn)】物聯(lián)網(wǎng)密碼柜之驅(qū)動(dòng)矩陣鍵盤(pán)和OLED顯示器

    +circuitpython進(jìn)行開(kāi)發(fā),矩陣鍵盤(pán)驅(qū)動(dòng)為自行編寫(xiě),Oled驅(qū)動(dòng)基于Adafruit SSD_1306庫(kù)。 到本階段為止已實(shí)現(xiàn)的功能: 矩陣鍵盤(pán)的輸入與識(shí)別 密碼校驗(yàn) 邊緣檢測(cè)及錯(cuò)誤處理 SSD1306顯示器的驅(qū)動(dòng)
    發(fā)表于 08-04 23:04

    覆冰精靈:守護(hù)電網(wǎng)安全的智能監(jiān)測(cè)裝置

    覆冰精靈,你以為是“調(diào)皮搗蛋的讓線路覆冰的小精靈嗎”?不不不,別理解錯(cuò)了,這可不是幫助線路覆冰的,覆冰精靈是監(jiān)測(cè)線路覆冰情況的“小幫手”。 電線積冰是電網(wǎng)常見(jiàn)的“覆冰”隱患,主要發(fā)生在氣候寒冷、濕度
    的頭像 發(fā)表于 07-23 18:31 ?564次閱讀

    【AWTK使用經(jīng)驗(yàn)】如何實(shí)現(xiàn)序列幀動(dòng)畫(huà)

    目前想在AWTK中顯示炫酷流暢的圖片動(dòng)畫(huà),此時(shí)可以用video_image控件來(lái)播放序列幀動(dòng)畫(huà)。本篇文章將介紹該控件的原理和使用方法。圖1ZTP800示教器運(yùn)行v
    的頭像 發(fā)表于 07-18 08:25 ?854次閱讀
    【AWTK使用經(jīng)驗(yàn)】如何實(shí)現(xiàn)序列幀<b class='flag-5'>動(dòng)畫(huà)</b>