Arduino Adafruit NeoPixel LED matrix is not working properly

Viewed 28

I'm new to Arduino development, trying to display alphabets in an 8x8 LED matrix, but the simulation is not working

The code was working fine with one letter, what am I doing wrong in the below example?

How to debug code and is there any way to add print statements in tinkercad simulation?

#include <Adafruit_NeoPixel.h>

#define PIN 4 // input pin Neopixel is attached to

#define NUMPIXELS 64 // number of neopixels in strip

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

const int8_t alphas[26][NUMPIXELS] = {
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
:
: // alphabet values
:
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};

uint8_t i = 0;

void setup()
{
  pixels.begin();
}

void loop()
{
  delay(2500);
  if (i == 26)
  {
    i = 0;
  }

  for (uint8_t j = 0; j < 64; j++)
  {
    int8_t pix = alphas[i][j];
    if (pix == 1)
    {
      pixels.setPixelColor(j, pixels.Color(255, 0, 0));
    }
    else
    {
      pixels.setPixelColor(j, pixels.Color(255, 255, 255));
    }
  }
  pixels.show();
  ++i;
}

tinkercad sim

1 Answers

In setup function you should have:

void setup()
{
  pixels.begin();
  pixels.show();
}
Related