Questions tagged [constants]

Constants in programming are definitions whose value is fixed throughout a program's execution. Literals in most languages are constants, for example. In referentially transparent programming styles, all definitions are constant.

Filter by
Sorted by
Tagged with
-1
votes
1answer
46 views

How to Set Sensor Data Parameters?

Good day! How to set sensor Data parameters? Like the data only set for example it starts with minimum value of 3 and ends with maximum value of 6 and it will turn on led 1 and if minimum value of 1 ...
0
votes
1answer
43 views

Creating an array with the length coming from a library

When creating an array like in the sketch #include <Lib.h> int myArray[Lib::len]; void setup() {} void loop() {} the variable len must be an integer constant that is known at compile time. ...
1
vote
1answer
128 views

#define above static const int?

I see a lot of people, but also libraries, defining constants (like pin numbers, length of items etc) as #define: #define LENGTH 5 While it is recommended to use in this case static const int: ...
-1
votes
1answer
253 views

Optimizing for speed using const, static, constexpr etc in a function

In an ISR I want to keep things quick. At the same time I want to limit variable scope. Storage space is not a factor. I have this line: const char trigs[] = "aAbBcCdDeEfFgGhHiIjJ"; When this is ...
2
votes
1answer
126 views

Syntax of binary Constants

I was trying to compile some Arduino code on the PC for testing when I noticed some strange syntax for numerical binary constants. Convetion seems to be to declare them like so: static const ...
1
vote
1answer
217 views

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

I'm working on a project for the arduino uno for which I need multiple constant arrays of bytes. Such an array is initialized like so: const byte charR[] PROGMEM = { B01111111,//top half ...
0
votes
1answer
435 views

String & Char concatenations

A newbie in Arduino- and I'm trying to concatenate string and chars ( well in python it is quite different ). I'm trying to post a MQTT message- constructed following format to the client.publish(...
2
votes
2answers
266 views

How to determine the source of constants in libraries?

Preamble: I am trying to figure out how to program and use the timers in the Feather M0 using the Arduino IDE. I have seen a number of examples published, but I'm not one to just blindly copy some ...
1
vote
2answers
1k views

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

I'm working on a project where I need to create a JSON to send back state of an object. I created the code to achieve it and all works fine, but I used this to declare the JSON fields: static const ...
1
vote
2answers
9k views

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

Why I'm getting this error? invalid conversion from 'const char*' to 'char' [-fpermissive] Here is my simple sketch: const char data = "should"; //I have also tried: //const char* data = "should"; ...
0
votes
1answer
44 views

Constants within array of structs causes strange compiler errors?

In my sketch I have the following: #define HU_ADDR 0x190; #define ALL_AUDIO_ADDR 0x1FF; #define MY_ADDR 0x360; #define UNKNOWN_ADDR 0xFFF; typedef ...
0
votes
0answers
45 views

Group of constants

I'm working on a project which involves a radio module. I'm currently writing a class I'm going to use to communicate with the radio (so that in my program I'll just have to writhe things like myRadio....
0
votes
1answer
4k views

What is causing this 'narrowing conversion' warning?

Because I'm still figuring out 'Arduino C' I leave all warnings on. Recently I got this one: narrowing conversion of '(int)(((unsigned char)bx_0) | ((unsigned char)bx_1))' from 'int' to 'const byte.....
-1
votes
1answer
83 views

const int re-declaration - memory leakage

I am re-declaring a const int variable a few times in a switch-case statement of a function as shown following: void functionB(type param1, type param2, ..., const int paramConstInt = 100); void ...
0
votes
1answer
816 views

Difficulties with raw string literals

I have an application where I would like to include an external multiline script as a const in my sketch. As far as I understand from C++11, this should work: raw_string_literal_test.ino const char *...
1
vote
4answers
4k views

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

I'm implementing a voice synthesizer chip. To build a phrase, I create a list of phonemes like this: static const uint8_t PROGMEM heybuddy[] = { pPA5, pHH1, pEY, pPA5, pBB2, pAX, pDD2, pIY, pPA5,...
3
votes
2answers
887 views

Const Array still using dynamic RAM during compile, causing failure

Using win7 and arduino 1.6.7 IDE I have a rather large CONST array of chars and upon compile using atmega2560, it fails and says: Sketch uses 11,216 bytes (4%) of program storage space. Maximum is ...
23
votes
4answers
4k views

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

Why do people use a variable to specify a pin number when the pin is unlikely to change throughout the execution of the code? Many times I see an int being used for a pin definition, int led = 13; ...