Clearing half an LED matrix with the adafruit neomatrix library.

Hello,

I am working on a scoreboard using a 32w x 8h led matrix. I have two buttons controlling each players score. Player one is on the left side of the matrix and player two on the right. I got the scores to show up. However, they keep flashing really fast. I think this is due to the "matrix.fillScreen(0);" function which is clearing the whole screen. I also have a message set to display when the winning score(21) is reached it will display a scrolling message saying "Winner Player1(or 2)"My reasoning for that is because I was able to get one side working perfectly without flashing rapidly. Is there a command that will only clear half the matrix?

Nick

scoreboard2.0.ino (3.07 KB)

Hi Nick, please post your code as explained in the forum guide. Most forum members use smartphones & tablets and can't open .ino files.

But the secret is not to clear half the display. The trick is not to clear it at all unless it needs to change.

PaulRB:
Hi Nick, please post your code as explained in the forum guide

I asked nicely, didn't I? I said please.

#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>

#define PIN 6
#define DataPin  6
#define NumLeds 256
#define Brightness 25
#define LED_Type WS2812B
#define ColorOrder GRB

CRGB leds[NumLeds];

int upPin = 13;
int downpin = 12;

int buttonplus = 0;
int buttondown = 0;
int number = 0;

int upPin2 = 11;//player2
int downpin2 = 10;

int buttonplus2;
int buttondown2;
int number2 = 0;

int x    = 32;
int pass = 0;

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN,
  NEO_MATRIX_BOTTOM    + NEO_MATRIX_RIGHT +
  NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
  NEO_GRB            + NEO_KHZ800);

const uint16_t colors[] = {
  matrix.Color(0,255,0), 
  };

void setup() {
  // put your setup code here, to run once:
FastLED.addLeds<LED_Type, DataPin, ColorOrder>(leds, NumLeds);
FastLED.setBrightness(Brightness);
pinMode(13, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
number = 0;
number2 = 0;
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(20);
  matrix.setTextColor(colors[0]);
}


void loop() {
  // put your main code here, to run repeatedly:
buttonplus = (digitalRead(upPin));
buttondown = (digitalRead(downpin));
if (buttonplus == 0) //if up button pressed score increases
{
  number = number + 1;
  delay(500);
}
if (buttondown == 0)//if down button pressed score decreases
{
  number = number - 1;
  delay(500);
}
if (number < 0)//if score goes below zero, the number will automatically equal zero again, preventing a negative score
{
  number = 0;
  delay(100);
}
if (number >= 21)//if player one score has reached the winning value display message saying who won
{
  matrix.fillScreen(0);
  matrix.setCursor(x,0);
  matrix.print(F("Winner Player1!!"));
  matrix.show();
  if( --x < -80 ) {
    x = matrix.width();

    if(++pass >= 8) pass = 0;
    matrix.setTextColor(colors[0]);
  }
  matrix.show();
  delay(50);
}
else  //display score
{
matrix.fillScreen(0);
matrix.setCursor(0,0);
matrix.print(number, DEC);
matrix.show();

}

if (buttonplus == 0)//reset
{
  if (buttondown == 0)
  {
    number = 0;
  }
}




buttonplus2 = (digitalRead(upPin2)); //player2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
buttondown2 = (digitalRead(downpin2));
if (buttonplus2 == 0)
{
  number2 = number2 + 1;
  delay(500);
}
if (buttondown2 == 0)
{
  number2 = number2 - 1;
  delay(500);
}
if (number2 < 0)
{
  number2 = 0;
  delay(100);
}
if (number > 20)
{
  matrix.fillScreen(0);
  matrix.setCursor(x,0);
  matrix.print(F("Winner Player2!!"));
  matrix.show();
  if( --x < -50 ) {
    x = matrix.width();

    if(++pass >= 8) pass = 0;
    matrix.setTextColor(colors[0]);
  }
  matrix.show();
  delay(50);
}
else
{
matrix.fillScreen(0);
matrix.setCursor(20,0);
matrix.print(number2, DEC);
matrix.show();

}

if (buttonplus2 == 0)//reset
{
  if (buttondown2 == 0)
  {
    number2 = 0;
  }
}
}

Update: I got the code working. I moved the clear screen function into the if statements for when the integer changes.

Hint: you can select "Modify" on your earlier post under the options at the bottom right of the post.

If the code is the same, you can then delete the second post, makes it all neater. :grinning: