This is progressing very nicely and I now have 1024 leds in colour.
In order to conserve RAM I got rid of two of the colour arrays for the NeoPixels and just kept a single array with RGB info in bits 5,6,7 and brightness info in bit 0-4.
So optimising code is my next priority.
The actual WS2812B led driving code is limited by strict timing protocols and is already in assembler so we will ignore that for now.
Evaluation of the 1024 grid life matrix must take some time so perhaps you can have a look at the code and if any glaring time sucking stuff leaps out make suggestions?
This part evaluates the primary 32 x 32 matrix and poulates a secondary 32 x 32 matrix with the updated information based on 'life' standard rules.
Code:
'----------------------- Also creating a newled data array to be displayed on next generation -------------
FOR counter = 0 TO 1023
population = 0 :topedge = 0 :botedge = 0 :lefedge = 0 :rigedge = 0
'Grid Edge Detection
IF counter < 32 THEN botedge = 1
IF counter > 991 THEN topedge = 1
IF counter = 0 OR counter = 32 OR counter = 64 OR counter = 96 OR counter = 128 OR counter = 160 OR counter = 192 OR counter = 224_
or counter = 256 OR counter = 288 OR counter = 320 OR counter = 352 OR counter = 384 OR counter = 416 OR counter = 448 OR counter = 480_
or counter = 512 OR counter = 544 OR counter = 576 OR counter = 608 OR counter = 640 OR counter = 672 OR counter = 704 OR counter = 736_
or counter = 768 OR counter = 800 OR counter = 832 OR counter = 864 OR counter = 896 OR counter = 928 OR counter = 960 OR counter = 992_
THEN
lefedge = 1
ENDIF
IF counter = 31 OR counter = 63 OR counter = 95 OR counter = 127 OR counter = 159 OR counter = 191 OR counter = 223_
or counter = 255 OR counter = 287 OR counter = 319 OR counter = 351 OR counter = 383 OR counter = 415 OR counter = 447 OR counter = 479_
or counter = 511 OR counter = 543 OR counter = 575 OR counter = 607 OR counter = 639 OR counter = 671 OR counter = 703 OR counter = 735_
or counter = 767 OR counter = 799 OR counter = 831 OR counter = 863 OR counter = 895 OR counter = 927 OR counter = 959 OR counter = 991_
THEN
rigedge = 1
ENDIF
'Grid Evaluation
IF led [counter-1] > 0 AND counter > 0 THEN
Colour[population] = led[counter-1]
population = population + 1
ENDIF
IF led [counter+1] > 0 AND counter < 1023 THEN
Colour[population] = led[counter+1]
population = population + 1
ENDIF
IF botedge = 0 THEN
IF led [counter-31] > 0 THEN
Colour[population] = led[counter-31]
population = population + 1
ENDIF
IF led [counter-32] > 0 THEN
Colour[population] = led[counter-32]
population = population + 1
ENDIF
IF rigedge = 0 and led [counter-33] > 0 THEN
Colour[population] = led[counter-33]
population = population + 1
ENDIF
ENDIF
IF topedge = 0 THEN
IF led [counter+31] > 0 THEN
Colour[population] = led[counter+31]
population = population + 1
ENDIF
IF led [counter+32] > 0 THEN
Colour[population] = led[counter+32]
population = population + 1
ENDIF
IF rigedge = 0 and led [counter+33] > 0 THEN
Colour[population] = led[counter+33]
population = population + 1
ENDIF
ENDIF
lednew[counter] = led[counter]
IF led[counter] > 0 THEN
IF population > 3 OR population < 2 THEN
lednew[counter] = 0
ENDIF
ENDIF
IF led[counter] = 0 THEN
IF population = 3 THEN
if Colour[0] = Colour[1] then
lednew[counter] = Colour[0]
elseif Colour[0] = Colour[2] then
lednew[counter] = Colour[0]
elseif Colour[1] = Colour[2] then
lednew[counter] = Colour[1]
else
lednew[counter] = led[counter] 'White LED
endif
ENDIF
ENDIF
NEXT counter
The second section moves data from the led matrix into the NeoPixel led array for display.
I previously posted about this due to the led matrix and NeoPixel matrix having a different layout.
It all works well at about 3hz but i'm looking for speed increases if possible.
Code:
alive = 0 'Clears alive accumulator
dead = 0 'Clears dead checksum accumulator
FOR Row = 0 to 31 ' Cycle thru 32 rows
FOR Col = 0 to 31 ' of 32 pixels each
InPtr = (Row * 32) + Col '
led[InPtr] = lednew[InPtr]
IF Row.0 = 0 THEN ' If the row number is even
OutPtr = InPtr ' Output pixels in true order
ELSE
OutPtr = (Row * 32) + (31-Col) ' Output pixels in reversed order
ENDIF
IF led[InPtr] > 0 THEN
NeoLed(OutPtr) = Led[InPtr]
alive = alive + 1
dead = dead + InPtr
else
NeoLed(OutPtr) = 0
ENDIF
NEXT
NEXT
The current colour code can be seen running in this short video.
Bookmarks