Skip to main content
4 votes
Accepted

Why I'm getting this error: invalid conversion from 'const char*' to 'char' [-fpermissive]?

const char data = "should"; In this case data is a single character, not a string. So it can store 's' but not "should". Serial.print("this " + data + " work"); No, that will never work, even if ...
Majenko's user avatar
  • 105k
4 votes
Accepted

Syntax of binary Constants

There is a file (binary.h) with every possible permutation of number between 0 and 255 represented as binary in it. They're stored as C-preprocessor macros: #define B0 0 #define B00 0 #define B000 0 #...
Majenko's user avatar
  • 105k
3 votes
Accepted

#define above static const int?

For numbers, certainly, const <type> is preferred. This is chiefly because it imposes a type (which would only be optional for a #define), which can have a knock-on effect for mathematics. ...
Majenko's user avatar
  • 105k
3 votes

Best practice to declare a 'static' text and save memory

The "traditional" way is to use PROGMEM and use const char * strings. I don't use the "traditional" way. Instead I use some "helper" classes and macros that WString.h provides. This does mean, ...
Majenko's user avatar
  • 105k
2 votes

Difficulties with raw string literals

Unlike other more "normal" build systems, the Arduino IDE doesn't compile the files in the project directory. Instead it loads all the files with certain extensions into the IDE, each in its own tab. ...
Majenko's user avatar
  • 105k
2 votes
Accepted

Initialize and read from a PROGMEM array of pointers to PROGMEM arrays

const byte* const message[] PROGMEM = to use an item, load it in RAM strcpy_P(buffer, (byte*)pgm_read_word(&(message[i]))); source Arduino reference - PROGMEM
Juraj's user avatar
  • 18.1k
2 votes
Accepted

String & Char concatenations

You can't simply concatenate C strings like that. Instead you have to build them up into a new string. For formatting like that the simplest way is with sprintf: char outMessage[strlen(outTopic) + ...
Majenko's user avatar
  • 105k
2 votes

Why use an int variable for a pin when const int, enum or #define makes much more sense

As a 2-week newbie to Arduino I'd pick up on the general idea of Arduino being occupied by non-programmers. Most sketches I have examined, including those on the Arduino site, show a total lack of ...
Jim's user avatar
  • 41
2 votes

How to know the data type of constant in arduino IDE?

From SPI.h: #ifndef LSBFIRST #define LSBFIRST 0 #endif #ifndef MSBFIRST #define MSBFIRST 1 #endif As you can see, there is no type. The compiler merely substitutes literally "1" for "...
Nick Gammon's user avatar
  • 38.6k
1 vote

Code explanation when pH sensor is connected to Arduino

This is a fine example why magic numbers are bad. Always use symbolic constants. Concerning the first line: The "5.0" is the reference voltage of the ADC, apparently 5.0 volts. The "...
the busybee's user avatar
  • 2,102
1 vote

Increase or decrease const byte value inside the code with a push button

The const keyword tells the C/C++ compiler that the variable is a constant and cannot be changed in your code anymore. Simply remove const and you can modify maxzyklus by using 2 digital inputs. byte ...
cat's user avatar
  • 177
1 vote
Accepted

How to Set Sensor Data Parameters?

For example: float basa = scale.get_units(); digitalWrite(led1, LOW); digitalWrite(led2, LOW); if( basa >= 2 && basa < 4 ) { digitalWrite(led2, HIGH); } if( basa >= 4 ) { ...
Peter Paul Kiefer's user avatar
1 vote
Accepted

How to determine the source of constants in libraries?

The name TC_CTRLA_PRESCALER_DIV1 indicates this is a macro. A trick for quickly finding the exact location of a macro definition is: File > Preferences > Compiler Warnings > All > OK In your sketch, ...
per1234's user avatar
  • 4,238
1 vote

How to determine the source of constants in libraries?

First of all, the definitions of these constants won't tell you very much. They just represent the registers and bits used in the datasheet of the microcontroller. If you do want to find their ...
tttapa's user avatar
  • 1,320
1 vote

Best practice to declare a 'static' text and save memory

const String does make nothing constant. You create an object, which can't be reassigned, but all methods work. Because it handles the characters inside and the const declaration doesn't change it. ...
Juraj's user avatar
  • 18.1k
1 vote

Why I'm getting this error: invalid conversion from 'const char*' to 'char' [-fpermissive]?

A char can only store one character. and const char* data can store a pointer to a string. You can copy it with strcpy: const char* data = malloc(7); if (data != 0) { strcpy(data, "should"); } ...
Michel Keijzers's user avatar
1 vote
Accepted

What is causing this 'narrowing conversion' warning?

That warning message arises when a compiler complies with C/C++ specifications. According to ISO/IEC 9899:2011 part 6.5.12.2 (“Bitwise inclusive OR operator”), Each of the operands shall have ...
James Waldby - jwpat7's user avatar
1 vote

How to pass a static const (progmem) array to a function

If you're not averse to a bit of C++: void sayPhrase(const uint8_t * phrase, size_t size) { bool open = false; for (size_t i = 0; i < size; ++i) { if(pgm_read_byte(phrase) != 4 ...
Pharap's user avatar
  • 149

Only top scored, non community-wiki answers of a minimum length are eligible