In attempting to test an Adafruit 2.8" TFT with Capacitive Touchpad, I discovered that LadyAda's graphicstest.ino example would not compile. Seems that it can't see the min() and max() functions.
I am using Arduino IDE revision 1.6.5
I boiled it down to a simple example - adding some math to the standard "blink" example.
// the setup function runs once when you press reset or power the board
void setup() {
int x,y,z;
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
x = 10;
y = 20;
z = min(x, y);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
The error message is as follows:
Arduino: 1.6.5 (Windows 7), Board: "Arduino Zero (Programming Port)"
Build options changed, rebuilding all
sketch_jun19b.ino: In function 'void setup()':
sketch_jun19b:10: error: 'min' was not declared in this scope
'min' was not declared in this scope
The exact same code compiles and runs properly on an Arduino Uno.
Thanks Denbo for verifying my observation about the built-in min() and max() functions.
Your work-around works for the simple case, but to get LadyAda's graphics library to compile correctly would require modification of her graphics subroutines - it would be more prudent for me to wait.
Is posting to this forum sufficient to alert the Arduino Zero team about this bug?
By the way it will work for the Adafruit_GFX library but it must be in the library itself after the include to Arduino.h. You can add in the last 3 lines of code as follows in Adafruit_GFX.h
#ifndef _ADAFRUIT_GFX_H
#define _ADAFRUIT_GFX_H
#if ARDUINO >= 100
#include "Arduino.h"
#include "Print.h"
#else
#include "WProgram.h"
#endif
// add in the next 3 lines
#undef min
inline int min(int a, int b) { return ((a)<(b) ? (a) : (b)); }
inline double min(double a, double b) { return ((a)<(b) ? (a) : (b)); }
It's a really weird bug, it seems that if "max" or "min" are defined, simply including <stdint.h> will make them disappear (undefine in some way? I coulnd't find where this happens exactly in stdint.h....)
BTW I've opened a pull request with a fix here:
if someone could try it before merging that would be wonderful.