Jeff it displayed the character/pattern correctly.
Progress! The next step would be to display a string of several characters.
Note that calculation of the pixel number using r or c values that could not fit on the display will, in some cases, give a LED number that is valid. It is important that you do not attempt to display a value from the frame buffer that uses a r or c value that could not fit on the frame. That constraint must be part of any code that displays more than one character.
Jeff,
Much better than that I have it scrolling now. I still would like it to start from the right and scroll left. Also the font is pretty awful. However, here is the new code
import machine, neopixel, time, random, sys, os
import framebuf
ROWS = 8
COLS = 25
COLS8 = COLS * 8
LED_PIN = 16
NUM_LEDS = COLS * ROWS
def rgbto(r,g,b):
v = (g << 16) + (r << 8) + b
return(v)
def rgbfrom(v):
b = v & 255
g = (v >> 8) & 255
r = (v >> 16) & 255
#print("V={} R={} G={} B={}".format(v,r,g,b))
return (r,g,b)
# Calculate linear pixel from Column/Row coordinates
def linearPixel(row,col):
#Determine if row is odd or even
#Right to left pattern 0 to 24
"""
if row % 2 == 0:
i = (row * COLS) + col
else:
i = (row * COLS) + (COLS - 1) - col
"""
#Left to right pattern 24 to 0
if row % 2 == 0:
i = (row * COLS) + (COLS - 1) - col
else:
i = (row * COLS) + col
return(i)
try:
# 123456789.123456789.123456789.1234567
msg = "Micropython Rules! Raspberry Pi Pico"
np = neopixel.NeoPixel(machine.Pin(LED_PIN), NUM_LEDS, bpp=3)
# Comment out framebuf code while performing simple Neopixel patter tests
MSGCOLS = len(msg) * 8
fbuf = framebuf.FrameBuffer(bytearray(MSGCOLS * ROWS * 2), MSGCOLS, ROWS, framebuf.RGB565)
fbuf.fill(0x00)
fbuf.text(msg,0,0,1)
i = 0
m = 0
l = ""
for r in range(ROWS):
for c in range(len(msg)*8):
if fbuf.pixel(c,r) == 1:
l = l + "*"
else:
l = l + " "
print(l)
l = ""
for p in range(len(msg)*8):
for c in range(COLS):
for r in range(ROWS):
i = linearPixel(r,c)
if fbuf.pixel(c,r) == 1:
np[i] = (0,255,0)
else:
np[i] = (0,0,0)
np.write()
time.sleep(.1)
fbuf.scroll(-1,0)
time.sleep(5)
except KeyboardInterrupt as e:
sys.print_exception(e)
print("Exiting...")
except IndexError as e:
sys.print_exception(e)
print("4:Index out of range C={} R={} I={}".format(c,r,i))
except (Exception, NameError, RuntimeError) as e:
sys.print_exception(e)
print(f"Unexpected {e=}, {type(e)=}")
finally:
np.fill((0,0,0))
np.write()
Good to hear that you got it working properly.
It depends on what you want the scrolling to do. For instance, if the message has a fixed length then the easiest fix for starting at the right would be to include the leading spaces as part of the text string and scroll the buffer. If you are rotating a message the extra spaces automatically create a space between the end of the message and its next beginning.
But if you are displaying scrolling text that is continually being added to, like a tickertape, then it will probably be easier to do the scrolling in the text string rather than by scrolling the buffer. This is possible because you are updating the display in one quick process from the buffer, so the procedure where you modify the text string and copy it into the buffer will not create artifacts in the display. You will still include spaces at the start of the text, but they will disappear as you delete leading characters and add trailing characters. The advantage of doing it like this rather than using the buffer scroll feature is that it simplifies the procedure for figuring out when and where in the buffer you need to add new characters after each scroll.