GlowBit.py
Classes | Public Member Functions | Public Attributes | List of all members
glowbit.matrix8x8 Class Reference

Class for driving GlowBit Matrix 8x8 modules and tiled arrangements thereof. More...

Inheritance diagram for glowbit.matrix8x8:
Inheritance graph
[legend]
Collaboration diagram for glowbit.matrix8x8:
Collaboration graph
[legend]

Classes

class  _textScroll
 

Public Member Functions

def __init__ (self, tileRows=1, tileCols=1, pin=18, brightness=20, mapFunction=None, rateLimitFPS=-1, rateLimitCharactersPerSecond=-1, sm=0)
 Initialisation routine for GlowBit stick modules and tiled arrays thereof. More...
 
def printTextWrap (self, string, x=0, y=0, colour=0xFFFFFF)
 Prints a string of text to a tiled GlowBit Matrix 8x8 display, automatically wrapping to new lines as required. More...
 
def addTextScroll (self, string, y=0, x=0, colour=0xFFFFFF, bgColour=0x000000, update=False, blocking=False)
 Adds a line of scrolling text to the display. More...
 
def updateTextScroll (self)
 Update a scrolling text animation. More...
 
def remap8x8 (self, x, y)
 Maps an (x,y) coordinate on a tiled GlowBit Matrix 8x8 array to an internal buffer array index. More...
 
def drawChar (self, char, Px, Py, colour)
 Draw a single character to the display. More...
 
def updateRateLimitCharactersPerSecond (self, rateLimitCharactersPerSecond)
 Changes the 8x8 matrix display's update rate in units of "characters of scrolling text per second". More...
 
- Public Member Functions inherited from glowbit.glowbitMatrix
def pixelSetXY (self, x, y, colour)
 Sets the colour value of the GlowBit LED at a given x-y coordinate. More...
 
def pixelSetXYNow (self, x, y, colour)
 Sets the colour value of the GlowBit LED at a given x-y coordinate and immediately calls pixelsShow() to update the physical LEDs. More...
 
def pixelSetXYClip (self, x, y, colour)
 Sets the colour value of the GlowBit LED at a given x-y coordinate. More...
 
def pixelAddXY (self, x, y, colour)
 Adds the colour value to the GlowBit LED at a given (x,y) coordinate. More...
 
def pixelAddXYClip (self, x, y, colour)
 Adds the colour value to the GlowBit LED at a given (x,y) coordinate. More...
 
def getPixelXY (self, x, y)
 Returns the 32-bit GlowBit colour value of the LED at a given (x,y) coordinate. More...
 
def drawLine (self, x0, y0, x1, y1, colour)
 Draws a straight line between (x0,y0) and (x1,y1) in the specified 32-bit GlowBit colour. More...
 
def drawTriangle (self, x0, y0, x1, y1, x2, y2, colour)
 Draws a triangle with vertices (corners) at (x0,y0), (x1, y1), and (x2,y2). More...
 
def drawRectangle (self, x0, y0, x1, y1, colour)
 Draws a rectangle with upper-left corner (x0,y0) and lower right corner (x1, y1). More...
 
def drawRectangleFill (self, x0, y0, x1, y1, colour)
 Draws a rectangle with upper-left corner (x0,y0) and lower right corner (x1, y1). More...
 
def drawRectangleFillAdd (self, x0, y0, x1, y1, colour)
 Draws a rectangle with upper-left corner (x0,y0) and lower right corner (x1, y1). More...
 
def drawCircle (self, x0, y0, r, colour)
 Draws a circle with center (x0,y0) and radius r. More...
 
def newGraph1D (self, originX=0, originY=7, length=8, direction="Up", minValue=0, maxValue=255, colour=0xFFFFFF, colourMap="Solid", update=False)
 Wrapper method to create a graph1D object. More...
 
def updateGraph1D (self, graph, value)
 Updates a graph1D object, draws it to the display buffer. More...
 
def updateGraph2D (self, graph, value)
 Updates a 2D graph with a new value. More...
 
def lineDemo (self, iters=10)
 Demonstrate drawing an animated line.
 
def fireworks (self, iters=10)
 Demonstrate drawing randomly placed, randomly coloured, expanding circles. More...
 
def circularRainbow (self)
 Demonstration of a rainbow effect is pseudo-polar coordinates. More...
 
def rain (self, iters=200, density=1)
 A "digital rain" demonstration. More...
 
def textDemo (self, text="Scrolling Text Demo")
 Demonstrates creation of non-blocking scrolling text. More...
 
def bounce (self, iters=500)
 Draws a single pixel at a random coordinate and "bounces" it around the display.
 
def demo (self)
 Runs several demo functions.
 
- Public Member Functions inherited from glowbit.glowbit
def pixelsShow (self)
 Pushes the internal pixel data buffer to the physical GlowBit LEDs. More...
 
def pixelSet (self, i, colour)
 Sets the i'th GlowBit LED to a 32-bit GlowBit colour value. More...
 
def pixelSetNow (self, i, colour)
 Sets the i'th GlowBit LED to a 32-bit GlowBit colour value and updates the physical LEDs. More...
 
def pixelAdd (self, i, colour)
 Adds a 32-bit GlowBit colour value to the i'th LED in the internal buffer only. More...
 
def pixelSaturatingAdd (self, i, colour)
 Adds a 32-bit GlowBit colour value to the i'th LED in the internal buffer. More...
 
def pixelsFill (self, colour)
 Fills all pixels with a solid colour value. More...
 
def pixelsFillNow (self, colour)
 Fills all pixels with a solid colour value and updates the physical LEDs. More...
 
def blankDisplay (self)
 Blanks the entire GlowBit display. More...
 
def getPixel (self, N)
 Returns the 32-bit GlowBit colour value of the i'th LED. More...
 
def updateRateLimitFPS (self, rateLimitFPS)
 Sets a new value for the GlowBit display's frames per second (FPS) limiter. More...
 
def power (self)
 Calculates an estimate for the total power draw given the current display data. More...
 
def chaos (self, iters=100)
 Sets random colour values on every LED on the attached GlowBit display. More...
 
- Public Member Functions inherited from glowbit.colourFunctions
def wheel (self, pos)
 Converts an integer "colour wheel position" to a packed 32-bit RGB GlowBit colour value. More...
 
def rgbColour (self, r, g, b)
 Converts the r, g, and b integer arguments to a packed 32-bit RGB GlowBit colour value. More...
 
def glowbitColour2RGB (self, colour)
 Converts a 32-bit GlowBit colour value to an (R,G,B) tuple. More...
 
def red (self)
 Returns the GlowBit colour value for pure red.
 
def green (self)
 Returns the GlowBit colour value for pure green.
 
def blue (self)
 Returns the GlowBit colour value for pure blue.
 
def yellow (self)
 Returns the GlowBit colour value for yellow.
 
def purple (self)
 Returns the GlowBit colour value for purple.
 
def cyan (self)
 Returns the GlowBit colour value for cyan.
 
def white (self)
 Returns the GlowBit colour value for white.
 
def black (self)
 Returns the GlowBit colour value for black.
 
- Public Member Functions inherited from glowbit.colourMaps
def colourMapSolid (self, index, minIndex, maxIndex)
 Trivial colourmap method which always returns the colour in the parent object. More...
 
def colourMapRainbow (self, index, minIndex, maxIndex)
 Maps the pure hue colour wheel between minIndex and maxIndex. More...
 

Public Attributes

 tileRows
 
 tileCols
 
 numLEDs
 
 numLEDsX
 
 numLEDsY
 
 numCols
 
 numRows
 
 sm
 
 pixelsShow
 
 ticks_ms
 
 strip
 
 ar
 
 dimmer_ar
 
 brightness
 
 scrollingText
 
 lastFrame_ms
 
 rateLimit
 
 scrollingTextList
 
 remap
 
 updateText
 
- Public Attributes inherited from glowbit.glowbit
 lastFrame_ms
 
 rateLimit
 

Additional Inherited Members

- Static Public Attributes inherited from glowbit.glowbit
 sideset_init
 
 OUT_LOW
 
 out_shiftdir
 
 SHIFT_LEFT
 
 autopull
 
 True
 
 pull_thresh
 

Detailed Description

Class for driving GlowBit Matrix 8x8 modules and tiled arrangements thereof.

The GlowBit Matrix 8x8 is designed to tile in two dimensions to create arbitratily large displays without the need for "air-wiring" of the data signal.

The remap8x8() method maps an (x,y) coordinate to a pixel index if the data signal "snakes" back and forth. When viewed from the REAR of a tiled array data-in is soldered to the top right module, moves right to left, then left to right on the 2nd row, etc. See https://glowbit.io/02 for assembly details.

  ---<  Data routing: view from REAR (ie: when soldering Din / Dout pads).
 |
  >---
     |
  ---<

Constructor & Destructor Documentation

◆ __init__()

def glowbit.matrix8x8.__init__ (   self,
  tileRows = 1,
  tileCols = 1,
  pin = 18,
  brightness = 20,
  mapFunction = None,
  rateLimitFPS = -1,
  rateLimitCharactersPerSecond = -1,
  sm = 0 
)

Initialisation routine for GlowBit stick modules and tiled arrays thereof.

Parameters
tileRowsThe number of tiled GlowBit Matrix 8x8 module rows.
tileColsThe number of tiled GlowBit Matrix 8x8 module columns.
pinThe GPIO pin connected to the GlowBit stick module. Defaults to 18 as that pin is compatible with the Raspberry Pi and Raspberry Pi Pico. Any pin can be used on the Raspberry Pi Pico, only pins 18 and 12 are valid on the Raspberry Pi.
brightnessThe relative brightness of the LEDs. Colours drawn to the internal buffer should be in the range [0,255] and the brightness parameter scales this value before drawing to the physical display. If brightness is an integer it should be in the range [0,255]. If brightness is floating point it is assumed to be in the range [0,1.0].
mapFunctionA function pointer to a custom pixel mapping function. Only required if mapping pixels to non-standard tiling arrangements.
rateLimitFPSThe maximum frame rate of the display in frames per second. The pixelsShow() function blocks to enforce this limit. This argument defaults to -1 to allow rateLimitCharactersPerSecond to preference this parameter if it is not set. If neither rateLimitFPS or rateLimitCharactersPerSecond are set the limit is set to 30 FPS.
rateLimitCharactersPerSecondIf given a positive value the display update rate is set to display this many characters of scrolling text per second. A value of 1 is fast, but readable. This value can be fractional (eg: 0.5).
sm(Raspberry Pi Pico only) The PIO state machine to generate the GlowBit data stream. Each connected GlowBit display chain requires a unique state machine. Valid values are in the range [0,7].

Member Function Documentation

◆ addTextScroll()

def glowbit.matrix8x8.addTextScroll (   self,
  string,
  y = 0,
  x = 0,
  colour = 0xFFFFFF,
  bgColour = 0x000000,
  update = False,
  blocking = False 
)

Adds a line of scrolling text to the display.

This method can be blocking or non-blocking.

If blocking the scrolling text will be drawn to the physical display and the method won't return until the animation is complete.

If non-blockig this method will return quickly, allowing subsequent calls to updateTextScroll() to control the rate of scrolling text animation. The text will scroll to the left one pixel with each call to updateTextScroll().

The update prameter is provided for convinience; if it is set to True a call to updateTextScroll() will automatically call pixelsShow(). Setting update to False allows the text scroll to be synchronised with other drawing updates.

Parameters
stringThe string of text to scroll across the display
yThe y coordinate of the top edge of the text
xThe initial location of the text relative to the right edge of the display. Setting positive will scroll the text from further off the edge, producing a delay before it is visible. Setting negative will cause the text to appear on the display instantly before scrolling to the left. In units of pixels.
colourThe colour of the scrolling text characters. A 32-bit GlowBit colour value
bgColourThe colour of the background (ie: all pixels in the 8-row high area the text is drawn to which aren't part of a character). A 32-bit GlowBit colour value.
updatePassing update = True causes updateTextScroll() to call pixelsShow(). Otherwise pixelsShow() must be called manually, allowing synchronisation of scrolling text with other animated features.
blockingPassing blocking = True will draw the scrolling text to the screen immediately and this method will not return until the text has scrolled off the display.

◆ drawChar()

def glowbit.matrix8x8.drawChar (   self,
  char,
  Px,
  Py,
  colour 
)

Draw a single character to the display.

For increased performance on Micropython boards this method uses the Micropython Viper code emitter so all arguments are necessary.

See also: addTextScroll() / updateTextScroll() for built-in scrolling text and printTextWrap() for printing static text with automatic line feeds.

Parameters
charA single character string. This character will be drawn to the internal buffer.
PxThe x coordinate of the upper left corner of the character. Characters occupy an 8x8 pixel area.
PyThe y coordinate of the upper left corner of the character. Characters occupy an 8x8 pixel area.
colourA 32-bit GlowBit colour value

◆ printTextWrap()

def glowbit.matrix8x8.printTextWrap (   self,
  string,
  x = 0,
  y = 0,
  colour = 0xFFFFFF 
)

Prints a string of text to a tiled GlowBit Matrix 8x8 display, automatically wrapping to new lines as required.

Each character occupies an 8x8 pixel area.

Characters which do not fit on the display are truncated.

Parameters
stringThe string to print to the display.
xThe x coordinate of the upper left corner of the first character
yThe y coordinate of the upper left corner of the first character
colourA 32-bit GlowBit colour value. All pixels in every character will be drawn in this colour.

◆ remap8x8()

def glowbit.matrix8x8.remap8x8 (   self,
  x,
  y 
)

Maps an (x,y) coordinate on a tiled GlowBit Matrix 8x8 array to an internal buffer array index.

It is recommended to use pixelSetXY() (and variants) instead of this function.

The return value can be passed to pixelSet(i, colour) (and its variants pixelSetNow() etc) in place of the paramter "i".

The (x,y) coordinates assume (0,0) in the upper left corner of the display with x increasing to the right and y increasing down

This function does not do boundary checking and may return a value which is outside the array, causing an IndexError exception to be raised.

Parameters
xThe x coordinate of the pixel to index
yThe y coordinate of the pixel to index

◆ updateRateLimitCharactersPerSecond()

def glowbit.matrix8x8.updateRateLimitCharactersPerSecond (   self,
  rateLimitCharactersPerSecond 
)

Changes the 8x8 matrix display's update rate in units of "characters of scrolling text per second".

For example, a value of 2 would scroll 2 charcters per second; leaving each character at least partly visible for 0.5 seconds.

◆ updateTextScroll()

def glowbit.matrix8x8.updateTextScroll (   self)

Update a scrolling text animation.

addTextScroll() must be called at least once for scrolling text to be drawn to the display.


The documentation for this class was generated from the following file: