New answers tagged

0

There also a trick using compiler predefined macro. The advantage is it can print any type. #include <string> template <class T> std::string type_name() { std::string s = __PRETTY_FUNCTION__; s.erase(0, s.find("[with T = ") + 10); s.erase(s.find(';')); return s; } Use it like this double pi = 3.14; const char* str = &...


1

I tested the template form and the long-hand form and got different results. See the last two rows of the table for the differences. Template Form MAKE_TYPE_INFO( bool ) MAKE_TYPE_INFO( bool* ) MAKE_TYPE_INFO( char ) MAKE_TYPE_INFO( char* ) MAKE_TYPE_INFO( double ) MAKE_TYPE_INFO( double* ) MAKE_TYPE_INFO( float ) MAKE_TYPE_INFO( float* ) MAKE_TYPE_INFO( int ...


3

Building on @snakeNET's answer (which I regard as function overload rather than polymorphism)... A more generic way would be to pass in a pointer to Print, allowing any Print related class to be used (not just Serial); also pass objects by reference e.g. void types(Print* p, const String&) { p->print("it's a String"); } // for each type ... ...


2

A bool value must be either 0 or 1, or false and true respectively. It is undefined behavior for it to be any other value. When assigning a value to a bool, the compiler will automatically force it to be 0 if it is already 0, or 1 if it is not. However, as it is a full byte, it is possible to store another value. As mentioned before, however, this is ...


1

A bool is literally that - a boolean value. So either 1 or 0 - true or false. In C only pointers can be NULL. Every other primitive type is a value, and NULL is not a value.


1

I do not really understand what may be the cause of your problem, but I have identified two issues that could potentially be related. You have: dutyCycle = map(readKnob, 1, 1023, 1, 8); Because of some rounding issues in the Arduino map() function, this may not work as you expect: the output will be 8 only if the input reaches 1023. If readKnob is 1022, ...


Top 50 recent answers are included