Hi all,
I have some scrolling text code for a pair of neopixel matrixes.
I want to change the colour of individual characters. I can’t work out how to do that using the print function at present from the NeoMatrix library.
Can anyone chip in and suggest a way to set the colour of each character in my strings?
Thanks!
/*
Example "Protest scroller" for 8x32 WS2812 "NeoPixel Display
Assumes you are running a standard Arduino ATMega328 compatible board
*/
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#include "FORCED_SQUARE5pt7b.h"
// DATA PIN
// If you want to use a different data pin on your microcontroller CHANGE THIS!
#define DATA_PIN 6
#define arr_len( x ) ( sizeof( x ) / sizeof( *x ) )
// Matrix setup params
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix( 32, 8, 2, 1, 6, NEO_MATRIX_BOTTOM + NEO_MATRIX_RIGHT +
NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
// Edit this
// The important stuff, your message and colors
char* Text[]= {
"while expectations >= achievements {",
"/ / / / / /",
"happiness -= currentMood('emotion');",
"# # # # # #",
"depression = true;",
"if lonely {",
"stranger = instance_nearest(x,y,human);",
"if stranger.single {",
"fillMyVoid(stranger);}}",
"else {"
"if drugInventory > 0 {",
"var q = random_range(1,currentTolerance);",
"use(drugs[random(drugXP)],q);"
"}",
"else { ",
"playAudio('black waves.mp3');"
"cry = true;",
};
const uint16_t colors[] = {
matrix.Color(59, 163, 255), matrix.Color(255, 110, 233),matrix.Color(84, 176, 255), matrix.Color(255, 179, 59), matrix.Color(116, 255, 71)};
//matrix.Color(0, 255, 0)};
int brightness = 50;
// End Edit
int numMode = arr_len(Text)-1;
int numColor = arr_len(colors)-1;
int pixelPerChar = 4;
int maxDisplacement;
int mode = 0;
int delayTime = 0;
void setup() {
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(brightness);
matrix.setTextColor(colors[0]);
matrix.setFont(&FORCED_SQUARE5pt7b);
}
int y = matrix.height();
int x = matrix.width();
int pass = 0;
int line_pass = 0;
void loop() {
// matrix.setBrightness(random(150));
// if mode greater than numMode reset
if (mode > numMode) { mode = 0; }
//matrix.fillScreen(matrix.Color(0,0,255));
matrix.fillScreen(0);
matrix.setCursor(x, 6);
scroll(Text[mode],delayTime);
}
// this does the magic of scrolling
void scroll(char* message,int delays) {
maxDisplacement = strlen(message) * pixelPerChar + matrix.width() + 10;
if(++line_pass > matrix.width()) line_pass = 0;
matrix.print(String(message));
if(--x < -maxDisplacement) {
x = matrix.width();
if(++pass >= numColor) { pass = 0; };
matrix.setTextColor(colors[pass]);
mode++;
}
matrix.show();
delay(delays);
}