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.
21 questions
1 vote
1 answer
710 views
Code explanation when pH sensor is connected to Arduino
I have to measure the pH value for some experiment. I have checked various codes and all include the average of pH values. #define SensorPin 0 // the pH meter Analog output is connected with ...
1 vote
1 answer
692 views
How to know the data type of constant in arduino IDE?
For example constant of MSBFIRST, It used to as input in SPI.setBitOrder(MSBFIRST). But sadly i don't know the type data of MSBFIRST. This is applied to like SPI_MODE0 and other.
1 vote
0 answers
460 views
Can data be stored in program storage space instead of dynamic memory?
I'm declaring an array at top level like so: constexpr byte a[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; // whatever data I'm referencing the array in such a way that it's not optimized away. When ...
3 votes
1 answer
373 views
Increase or decrease const byte value inside the code with a push button
I'm kind of new in the Arduino world. I decided to make a self learning project with an Arduino where it controls a conveyor that simply moves from right to left and back again. There is a start and ...
-1 votes
1 answer
120 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
1 answer
149 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
1 answer
304 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
1 answer
977 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
1 answer
415 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
1 answer
790 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
1 answer
2k 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
2 answers
446 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 ...
2 votes
2 answers
3k 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 ...
2 votes
2 answers
25k 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
1 answer
60 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 ...