NeoPixel neo_16x16 to neo_10x10
DHavron opened this issue · 1 comments
DHavron commented
Hi!
Using your neo_16x16 code to customize neo_10x10 :
test.py
from machine import Pin
import time
from neo10x10 import neo10x10
np = neo10x10(Pin(5))
npdat=[
0x00, 0x66, 0x66, 0xe0, 0xe0, 0xe0, 0xe0, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
]
n = 0
while 1:
np.show(npdat, n)
n = (n-10)%10
time.sleep_ms(100)
neo10x10.py
from machine import Pin
import neopixel
class neo10x10:
def __init__(self, pin):
self.np = neopixel.NeoPixel(pin, 100)
self.color = (0,0,8)
def clear(self):
self.np.fill((0,0,0))
self.np.write()
def set(self, n, color=''):
if color!='':
self.np[n] = color
else:
self.np[n] = self.color
self.np.write()
def setcolor(self, color):
self.color = color
def show(self, dat, offset=0, clear = True, color=''):
if color != '':
self.color = color
if clear:
self.np.fill((0,0,0))
num = 0
for x in range(10):
for y in range(10):
if (x+offset)>=len(dat):
self.np[x*10+y]=(0,0,0)
else:
if (1<<y)&dat[x+offset]:
if offset%2==0:
self.np[x*10 + y] = self.color
else:
self.np[x*10 + 9 - y] = self.color
self.np.write()
trying to display an image smile
I get this output
what could be the problem?
tell me in which editor to convert the image into an array of data?
shaoziyang commented
In neo16x16, use 1bit for a ws2812 or one byte for 8 ws2812, so 10x10 matrix need 100/8=12.5 bytes. It is not an integer and will cause some trouble.
I suggest use neo16_x16_img, it use 4bit for one of ws2812 color (to save microbit memory), and and 10x10 matrix need 100*3=300 bytes.
And I have wrote a small program microbit_toolbox to convert images, it is for microbit but with few modify it will work for other device. Or delete redundant data after convert.