-2

So I wrote a script in Processing that can output the HEX values of every pixel of any given image into an array. Im trying to get this FastLED library to read the Array and Im getting so many different errors. I tried changing the HEX's to strings I used FF and 0x headers. Nothing seems to works. Right now it keeps saying the Hex values aren't declared in the scope. If I change the hexes to strings I get a function error that tells me that they aren't stings. Im at wits end. Here's the code.

#include <FastLED.h>

#include <LEDMatrix.h>
#include <string.h>
// Change the next 6 defines to match your matrix type and size

#define LED_PIN        7
#define COLOR_ORDER    GRB
#define CHIPSET        WS2811

#define MATRIX_WIDTH   32  // Set this negative if physical led 0 is opposite to where you want logical 0
#define MATRIX_HEIGHT  8  // Set this negative if physical led 0 is opposite to where you want logical 0
#define MATRIX_TYPE    VERTICAL_ZIGZAG_MATRIX  // See top of LEDMatrix.h for matrix wiring types


cLEDMatrix<MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_TYPE> leds;

char pixs [] = {{FFCE2131},
{FFCE1929},
{FFCE1929},
{FFCE1929},
{FFCE1929},
{FFCE1929},
{FFCE1929},
{FFCE2131},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFCE1929},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFCE1929},
{FFCE1929},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFCE1929},
{FFCE1929},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFCE1929},
{FFCE1929},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFCE1929},
{FFCE1929}};



void setup()
{
  FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds[0], leds.Size());
  FastLED.setBrightness(15);
  FastLED.clear(true);
  delay(500);
  FastLED.clear(true);
  Serial.begin(9600);

}

void loop() {



leds(0,0) = 0xCE2131;
leds(31,0) = CRGB::White;
leds(0,7) = CRGB::Green;
leds(31,7) = CRGB::Yellow;
FastLED.show();
delay(2000);
FastLED.clear(true);
delay(1000);

int i;
for ( i = 0; i < length.pixs ; i ++){
  leds(0,0) = pixs[i];
  FastLED.show();
}

}
Joel Spolsky
  • 32,422
  • 17
  • 82
  • 101
  • 2
    Welcome to Stack Overflow. Please read the [About] and [Ask] pages soon. You're stepping into delicate territory by tagging your question with both C and C++ tags. Choose the language you want to work in and stick with just that tag — either C or C++ but not both. Answers that are appropriate to one language are often not appropriate to the other. – Jonathan Leffler Aug 24 '17 at 23:05
  • 2
    Remove the C language tag. The C language does not support templates, such as `cLEDMatrix leds;`. Try compiling with a C language compiler and that statement should generate some errors. Likewise with the scope resolution operator `::`. – Thomas Matthews Aug 24 '17 at 23:08
  • 1
    Note that the line `char pixs [] = {{FFCE2131},` displays multiple problems. You have a single-dimensional array, but the double braces can only be used with more complex structures (2D arrays or actual C structures). The value `FFCE2131` is an identifier not a hex number. You'd need `0xFFCE2131` for it to be hex. You can't usually fit 4 bytes of data into a single byte object. – Jonathan Leffler Aug 24 '17 at 23:08
  • Are the `FFC` names identifiers or are they hex constants. As hexadecimal contents, they don't fit into a char type. – Thomas Matthews Aug 24 '17 at 23:10

1 Answers1

1

Evolution took about 4 billion years, that is a good indication that programming by random mutation is not a good idea. I don´t have arduino and I don´t have a hardware setup to test the code and your description is not sufficient to precisely guess what you are going to do. That said:

What do you expect

length.pixs

could mean or do? C++ idiom would suggest to use std::array I think, that would enable you to elegantly get the number of entries. Since you stick with C arrays, the length would be calculated by

sizeof(pixs)/sizeof(*pixs)

The array construction is defective, in your code you access the array being 1 dimensional and your type also indicates 1 dimensional. So it should be

unsigned long pixs [] = {0xCE2131, 0xCE1929, 0xCE1929}

and not your double braced list. Hex literals are given by using 0x, nothing else. 0xCE1929 and not FFCE1929 which has no meaning (despite being an identifier which is meaningless in your code)

The following version of your code is at least syntactically correct and should provide a basis for your further explorations.

#include <LEDMatrix.h>
#include <string.h>

#define MATRIX_WIDTH   32  // Set this negative if physical led 0 is opposite to where you want logical 0
#define MATRIX_HEIGHT  8  // Set this negative if physical led 0 is opposite to where you want logical 0
#define MATRIX_TYPE    VERTICAL_ZIGZAG_MATRIX  // See top of LEDMatrix.h for matrix wiring types


cLEDMatrix<MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_TYPE> leds;

unsigned long pixs [] = {0xCE2131,
    0xCE1929,0xCE1929,0xCE1929,0xCE1929,
    0xCE1929,0xCE1929,0xCE2131,0xC50821,
    0xC50821,0xC50821,0xC50821,0xC50821,
    0xC50821,0xC50821,0xC50821,0xCE1929,
    0xC50821,0xC50821,0xC50821,0xC50821,
    0xC50821,0xC50821,0xCE1929,0xCE1929,
    0xC50821,0xC50821,0xC50821,0xC50821,
    0xC50821,0xC50821,0xCE1929,0xCE1929,
    0xC50821,0xC50821,0xC50821,0xC50821,
    0xC50821,0xC50821,0xCE1929,0xCE1929,
    0xC50821,0xC50821,0xC50821,0xC50821,
    0xC50821,0xC50821,0xCE1929,0xCE1929};



void setup()
{
    FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds[0], leds.Size());
    FastLED.setBrightness(15);
    FastLED.clear(true);
    delay(500);
    FastLED.clear(true);
    Serial.begin(9600);
}

void loop() {
    leds(0,0) = 0xCE2131;
    leds(31,0) = CRGB::White;
    leds(0,7) = CRGB::Green;
    leds(31,7) = CRGB::Yellow;
    FastLED.show();
    delay(2000);
    FastLED.clear(true);
    delay(1000);

    for (int i = 0; i < sizeof(pixs)/sizeof(*pixs) ; i ++){
        leds(0,0) = pixs[i];
        FastLED.show();
    }

}
DrSvanHay
  • 1,160
  • 4
  • 15