Jaromanda X is indeed correct - min() is defined on line 92 of Arduino.h, thusly:
#define min(a,b) ((a)<(b)?(a):(b))
Therefore when the ++mycount is substituted for the a, it is in fact substituted twice, in both the (a)<(b) and the (a):(b), leading to the increment by 2, each time min(++mycount,8) is executed.
As VE7JRO mentions, as it is defined in this way, the reference for min(x,y) states:
Warning
Because of the way the min() function is implemented, avoid using
other functions inside the brackets, it may lead to incorrect results
min(a++, 100); // avoid this - yields incorrect results
min(a, 100);
a++; // use this instead - keep other math outside the function
As the second example states, keep any incrementing outside of the min() macro.
Alternatively, I think that you could use the inline function to workaround this issue:
#undef min
inline int min(int a,int b) {return ((a)<(b)?(a):(b)); }
Because inline provides a real function call (with parameters) it avoids the use of macros and substitution, which gives rise to the issue that you encountered.
inline is a much better (safer) way to implement the functionality provided by macros, in many cases. For more information, see Inline functions in C++ or read a C++ reference.
#define min(a,b) ((a)<(b)?(a):(b))think about what happens when you expandmin( ++myCount, 8 ).... you get((++myCount)<(8)?(++myCount):(8))- however, I didn't think it was a macro, so that's odd – Jaromanda X Dec 07 '18 at 08:23