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 ...
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
#...
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.
...
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, ...
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. ...
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
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) + ...
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 ...
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 "...
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 "...
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 ...
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 )
{
...
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, ...
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 ...
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. ...
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");
}
...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
constants × 21array × 5
arduino-uno × 3
c++ × 3
string × 3
c-preprocessor × 3
programming × 2
arduino-ide × 2
library × 2
memory-usage × 2
code-optimization × 2
compilation-errors × 2
data-type × 2
progmem × 2
compiler × 2
sensors × 1
nodemcu × 1
button × 1
variables × 1
switch × 1
pointer × 1
mqtt × 1
data × 1
struct × 1
samd21g × 1