Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

-1
votes
1answer
44 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
55 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
97 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
53 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
196 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
366 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 ...
0
votes
1answer
36 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
37 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
2k 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
70 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
600 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
2k 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
603 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
3k 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; ...