Skip to content

Commit f08a660

Browse files
authored
Merge pull request #2338 from adafruit/5x5_BFF_demos
Adding arduino and CP code for 5x5 BFF
2 parents 527a999 + bd08b8e commit f08a660

File tree

6 files changed

+145
-1
lines changed

6 files changed

+145
-1
lines changed

5x5_NeoPixel_BFF_Examples/Arduino_5x5_Scrolling_Text_Demo/.feather_rp2040.test.only

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// SPDX-FileCopyrightText: 2022 Phil B. for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
// Example for 5x5 NeoBFF - scrolls a message across the LED matrix.
6+
// Requires Adafruit_GFX, Adafruit_NeoPixel and Adafruit_NeoMatrix libraries.
7+
8+
#include <Adafruit_GFX.h> // Graphics library
9+
#include <Adafruit_NeoPixel.h> // NeoPixel library
10+
#include <Adafruit_NeoMatrix.h> // Bridges GFX and NeoPixel
11+
#include <Fonts/TomThumb.h> // A tiny 3x5 font incl. w/GFX
12+
13+
#define PIN A3
14+
15+
// NeoMatrix declaration for BFF with the power and
16+
// Neo pins at the top (same edge as QT Py USB port):
17+
Adafruit_NeoMatrix matrix(5, 5, PIN,
18+
NEO_MATRIX_TOP + NEO_MATRIX_RIGHT +
19+
NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE,
20+
NEO_GRB + NEO_KHZ800);
21+
22+
// Message to display, and a set of colors to cycle through. Because
23+
// the matrix is only 5 pixels tall, characters with descenders (e.g.
24+
// lowercase p or y) are best avoided. There are even smaller fonts
25+
// but these get progressively less legible. ALL CAPS helps!
26+
const char message[] = "HELLO BFF";
27+
const uint16_t colors[] = {
28+
matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
29+
uint16_t message_width; // Computed in setup() below
30+
31+
void setup() {
32+
matrix.begin();
33+
matrix.setBrightness(40); // Turn down brightness to about 15%
34+
matrix.setFont(&TomThumb); // Use custom font
35+
matrix.setTextWrap(false); // Allows text to scroll off edges
36+
matrix.setTextColor(colors[0]); // Start with first color in list
37+
// To determine when the message has fully scrolled off the left side,
38+
// get the bounding rectangle of the text. As we only need the width
39+
// value, a couple of throwaway variables are passed to the bounds
40+
// function for the other values:
41+
int16_t d1;
42+
uint16_t d2;
43+
matrix.getTextBounds(message, 0, 0, &d1, &d1, &message_width, &d2);
44+
}
45+
46+
int x = matrix.width(); // Start with message off right edge
47+
int y = matrix.height(); // With custom fonts, y is the baseline, not top
48+
int pass = 0; // Counts through the colors[] array
49+
50+
void loop() {
51+
matrix.fillScreen(0); // Erase message in old position.
52+
matrix.setCursor(x, y); // Set new cursor position,
53+
matrix.print(message); // draw the message
54+
matrix.show(); // and update the matrix.
55+
if(--x < -message_width) { // Move 1 pixel left. Then, if scrolled off left...
56+
x = matrix.width(); // reset position off right edge and
57+
if(++pass >= 3) pass = 0; // increment color in list, rolling over if needed.
58+
matrix.setTextColor(colors[pass]);
59+
}
60+
delay(100); // 1/10 sec pause
61+
}

CircuitPython_NeoPixel_BFF/code.py renamed to 5x5_NeoPixel_BFF_Examples/CircuitPython_Scrolling_Text/code.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
label = Label(text="Hello World!! Adafruit QT Py RP2040 + NeoPixel BFF ", font=font)
1414
bitmap = label.bitmap
1515

16-
pixels = neopixel.NeoPixel(board.A2, 5*5, brightness=.07, auto_write=False)
16+
pixels = neopixel.NeoPixel(board.A3, 5*5, brightness=.07, auto_write=False)
1717
pixels.fill(0)
1818
pixels.show()
1919
colors = [0, 0]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Jeff Epler for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
import time
5+
import board
6+
import neopixel
7+
import fontio
8+
from adafruit_display_text.bitmap_label import Label
9+
from adafruit_bitmap_font import bitmap_font
10+
from displayio import Bitmap
11+
from rainbowio import colorwheel
12+
13+
tom_thumb = bitmap_font.load_font("tom-thumb.pcf", Bitmap)
14+
15+
_glyph_keys = ['bitmap', 'tile_index', 'width', 'height', 'dx', 'dy', 'shift_x', 'shift_y']
16+
def patch_glyph(base, **kw):
17+
d = {}
18+
for k in _glyph_keys:
19+
d[k] = kw.get(k, getattr(base, k))
20+
return fontio.Glyph(**d)
21+
22+
class PatchedFont:
23+
def __init__(self, base_font, patches):
24+
self.base_font = base_font
25+
self.patches = patches
26+
27+
def get_glyph(self, glyph):
28+
g = self.base_font.get_glyph(glyph)
29+
patch = self.patches.get(glyph)
30+
if patch is not None:
31+
print("patching", repr(chr(glyph)), g)
32+
g = patch_glyph(g, **patch)
33+
print("patched", g)
34+
return g
35+
36+
def get_bounding_box(self):
37+
return self.base_font.get_bounding_box()
38+
39+
font = PatchedFont(tom_thumb,
40+
{
41+
32: {'shift_x': 1, 'dx': 0},
42+
105: {'dx': 0, 'shift_x': 2},
43+
33: {'dx': 0, 'shift_x': 2},
44+
})
45+
46+
label = Label(text=" adafruit! ", font=font)
47+
bitmap = label.bitmap
48+
49+
heart_bitmap = [
50+
0,1,1,0,0,
51+
1,1,1,1,0,
52+
0,1,1,1,1,
53+
1,1,1,1,0,
54+
0,1,1,0,0,
55+
]
56+
57+
pixels = neopixel.NeoPixel(board.A3, 5*5, brightness=.06, auto_write=False)
58+
59+
while True:
60+
for hue in range(0, 255, 3):
61+
color = colorwheel(hue)
62+
pixels[:] = [pixel * color for pixel in heart_bitmap]
63+
pixels.show()
64+
time.sleep(.01)
65+
66+
hue = 0
67+
for i in range(bitmap.width):
68+
# Use a rainbow of colors, shifting each column of pixels
69+
hue = hue + 7
70+
if hue >= 256:
71+
hue = hue - 256
72+
73+
color = colorwheel(hue)
74+
75+
# Scoot the old text left by 1 pixel
76+
pixels[:20] = pixels[5:]
77+
78+
# Draw in the next line of text
79+
for y in range(5):
80+
# Select black or color depending on the bitmap pixel
81+
pixels[20+y] = color * bitmap[i,y]
82+
pixels.show()
83+
time.sleep(.1)
Binary file not shown.

0 commit comments

Comments
 (0)