Ran into problems with the min and max function using ESP8266WiFi.h Arduino 1.6.4,

Ran into problems with the min and max function using ESP8266WiFi.h
Arduino 1.6.4, Feather Huzzah, ESP package 2.0.0
The sketch compiles; but not when ESP8266WiFi.h library is included. It returned ‘min’ was not declared in this scope.
I thought I found a fix by adding
#define min(X, Y) (((X)<(Y))?(X):(Y))
#define max(X, Y) (((X)>(Y))?(X):(Y))

When I use the function
RIGHT_PEAK = max(RIGHT_MAX, 0);
leds [RIGHT_PEAK] = CRGB::Red;

it crashes and resets:
Exception (9):
epc1=0x40206ee4 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000015 depc=0x00000000

ctx: cont
sp: 3fff1370 end: 3fff1640 offset: 01a0

Any hints ?

RIGHT_PEAK is larger than your array bounds. I don’t think it’s the min macro here. Check your values first.

@Peter_Buelow I constrained now the values but same effect
constrain(LEFT_MAX, 0, 71);
constrain(RIGHT_MAX, 0, 71);

also renamed the function to _min and _max; no improvement

I’m not so experienced in C++, maybe @Daniel_Garcia knows what’s the issue.

What is the value of NUM_LEDS? Also, you should upgrade to esp2.2.0 and probably Arduino 1.6.8 as well.

@Daniel_Garcia NUM_LEDS = 144, I tried all ESP-versions from 1.6, 2.0, 2.1, 2.2, also tried it with Arduino 1.6.8
The problem is not FastLED. ESP2.x does not support min and max and the moment
the library ESP8266WiFi.h is included it will disable this function also in Arduino.
Is it possible to fix the problem in the FastLED ESP8266 support?

Not sure why you want FastLED to fix the platform not defining min/max - especially since FastLED doesn’t use min/max? Also - I’d need to see your entire code to figure out why you are getting that crash - my guess is you’re writing outside of your array somewhere.

@Daniel_Garcia good point, I was just hoping. When I get back I’ll try to debug myself. It’s right now a 2000+ lines monster; I don’t think you want to go through that :wink:

Pin choice is important. Not sure which pins are using. esp12 has lots of pints broken out but you can only use a few of them.