AaronLiddiment / LEDText

FastLED Flexible Text Message Class requires LEDMatrix Class
89 stars 32 forks source link

How to call out CRGB.leds[i] while using LEDText #24

Closed CobaltEcho closed 2 years ago

CobaltEcho commented 2 years ago

Newer to programming, so hope this isn't something overly stupid.

I have the LEDText examples working, so looking to incorportate that into some other code I'm working on.

Per FastLED, I have CRGB leds[NumLeds];

Per LED Matrix/Text I have cLEDMatrix<DisplayWidth, DisplayHeight, HORIZONTAL_ZIGZAG_MATRIX> leds;

These lines both define leds from my understanding.

error: no matching function for call to 'CFastLED::addLeds<WS2812B, 9, GRB>(cLEDMatrix<14, 10, (MatrixType_t)2>&, const uint16_t&)'
   FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NumLeds);
error: wrong number of template arguments (3, should be 2)
   FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NumLeds);
error: lvalue required as left operand of assignment
 leds[35] = CRGB(255 , 0 , 0);

And a ton of others. How do I get CRGBto work with cLEDMatrix?

AaronLiddiment commented 2 years ago

A good place to start is to read the Wiki I created for the cLEDMatrix Class: https://github.com/AaronLiddiment/LEDMatrix/wiki cLEDText relys on my cLEDMatrix class and it is the Matrix class which allocates the CRGB array of leds therefore you do not need to allocate them with CRGB leds[NumLeds]; If you look at my examples you will notice that the array of leds is passed to Fastled with: FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds[0], leds.Size()); Then you can access the leds by Index or X/Y using the following syntax: leds(i) = CRGB::Red; or leds(x,y) = CRGB::Red If you need an address for the leds CRGB structure then you use leds[i], note the square brackets.

CobaltEcho commented 2 years ago

Thanks @AaronLiddiment , I did read through the Wiki and have had things set up as follows:

const uint8_t DisplayWidth = 14;
const uint8_t DisplayHeight = 10;
const uint16_t NumLeds = DisplayWidth * DisplayHeight;
const uint16_t NUM_LEDS = NumLeds;

cLEDMatrix<DisplayWidth, DisplayHeight, HORIZONTAL_ZIGZAG_MATRIX> leds;

FastLED.addLeds<WS2812B, 9, GRB>(leds[0], leds.Size());
FastLED.addLeds<WS2812B, 10, GRB>(leds[0], leds.Size());

Maybe these errors makes sense?

FastLED\src/pixeltypes.h:751:44: note: candidate: bool operator<(const CRGB&, const CRGB&) inline attribute((always_inline)) bool operator< (const CRGB& lhs, const CRGB& rhs)

FastLED\src/pixeltypes.h:751:44: note: no known conversion for argument 2 from 'cLEDMatrix<14, 10, (MatrixType_t)2>' to 'const CRGB&' MatrixTestv6:497:35: error: lvalue required as left operand of assignment leds[i] = CHSV(hue++, 255, 255);

error: request for member 'getAverageLight' in 'leds.cLEDMatrix<14, 10, (MatrixType_t)2>::.cLEDMatrixBase::operator)', *which is of pointer type 'CRGB'** (maybe you meant to use '->' ?) uint8_t l = leds[i].getAverageLight();

AaronLiddiment commented 2 years ago

Why do you have 2 addLeds lines? Do you have 2 led matrix connected? Unless you want both to display the same info you need to use different led arrays!

Please re-read my previous reply! There is a big difference between [] & ()! In my cLEDMatrix class I override [] to reference the address of CRGB class for that index but () to reference the CRGB class for the index.

CobaltEcho commented 2 years ago

Ahh, ok, I'm new to programming so I think I'm getting mixed up between address and reference.

So if I'm understanding correctly... So you would use leds(i) to use something built into the (class?), like cHSV to set the color for the led, but not specifically addressing that led for output.

But if you want to actually address the led, as in, set the led to something specific, you use the [i] to say "led i should be red".

CobaltEcho commented 2 years ago

So how would you do something like this, where it's assumed leds is an int?

for(int i = 0; i < leds; i++) {

error: no match for 'operator<' (operand types are 'int' and 'cLEDMatrix<14, 10, (MatrixType_t)2>')

Disreguard Question, but going to anwser in case someone in the future needs this info: Use Num_Leds (or the number of LED's you have) instead of leds:

for(int i = 0; i < NumLeds; i++) {

AaronLiddiment commented 2 years ago

Well for a start this is not really the place for me to teach you the basics of C++, what you really need to do is look up some online reasources for learning about c++ classes. A class consists of a definition for the class which will declare a number of variables, functions & operators that make up that class. So for exmaple my cLEDMatrix class has a function called Size() which returns the number of CRGB elements in the array. So you can use leds.Size() to return the number of LEDs you have. It would be a good idea for you to take a look at the examples and wiki for the cLEDMatrix class as this may answer your questions about it's usage. It will start to make sense once you study it a bit more. I have been doing it so long I forget how baffling it can be when you first start out.