adafruit / adafruit/Adafruit_CircuitPython_NeoPixel

Set pixels using slice with single color / multiple colors

Open
#97 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
329
Forks
96
PR merge metrics
No merged PRs in 30d

Description

Playing around with NeoPixel I thought of building some stuff on top using the slice syntax
i.e `pixels[:len(pixels)//2] = (255, 0 ,0)`
Which currently fails as the colors tuple must be at least the length of the slice

Using `pixels.fill((255,0,0)` could work, but only if you start at the beginning, not for arbitrary slices (i.e setting middle third with `third = len(pixels)//3` then `pixels[third: 2 * third] = (255, 0, 0)`

Bonus: if a tuple is given, but not of the same length, It could be cool if it just repeated, meaning:
`pixels[:7] = (R, G, B)` would set the pixels `(R, G, B, R, G, B, R)`

Since this would have thrown an error before, it should be backwards-compatible.

I realize all this can be done manually but since slices are already supported it seems like a nice intuitive feature :)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the existing NeoPixel slice-assignment implementation and the tests covering slice writes. Define the behavior for assigning one RGB tuple to an arbitrary slice, including the proposed repeated-tuple case, and consider compatibility with previously invalid assignments. Done means the requested slice examples work without breaking existing slice behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.