New answers tagged

1

If you want a "variable" that is used at compile time, for instance to set the size of an array, then a variable is not what you want. Variables change. That's what "variable" means. If you are using it for something at compile time then it can't be variable, since it must never change. Ergo, you want either a constant or a #define macro which is replaced ...


3

In Lib.h you should declare an extern int myVariable; In Lib.cpp you can define it once #include "Lib.h" int myVariable=123; ...


0

When creating a library with functions that are not mentioned in the header file, the order of appearence in the .cpp file suddenly becomes relevant. In order for a function to be used by another function, it has to be declared first. The first possibility in this example would be to define foo2 before defining foo1 like this: #include "Lib.h" // ...


0

There are two ways of doing this: Multiple INO files The Arduino IDE combines multiple INO files into one single CPP file before compilation. You can split your program across multiple INO files at will. It makes it easier to manage, since you can split your program into logical chunks at will, but you don't have to think much beyond "which file shall I ...


0

This is more like a general programming question than an Arduino question but, anyway... You don't need to write classes to sort your code into files. You just need to think in term of independent pieces of functionality. Each of those pieces would be implemented in a .cpp file, with the interface declared in a .h file. As an example, let's say your ...


1

If your library is implemented in a single .cpp file, you can define these variables and functions within that file, and give them the static qualifier: static int my_private_variable = 42; static void my_private_function() { ... } Obviously, there should be no mention of them in the .h file. Note also that we are talking about global variables. ...


3

If you enter 1 in Serial Monitor and you have line ends selected, the Serial Monitor sends "1\r\n". parseInt() reads 1 and in next loop \r or \n is available and parses as 0. You then set the Timer to 0. The Serial can't finish printing because the Timer fires without a pause.


-1

char buf[50]; char* tm1Txt (byte num){ if (num == 0){strcpy_P(buf, (char*) F("t1 - Задepжka koмaнды xoд"));} if (num == 1){strcpy_P(buf, (char*) F("t2 - Bpeмя cepвoфиkcaции "));} if (num == 2){strcpy_P(buf, (char*) F("t3 - Bpeмя дoтягивания "));} if (num == 3){strcpy_P(buf, (char*) F("t4 - Bpeмя тopмoжeния "));} if (num == 4){strcpy_P(buf, (...


0

I managed to change SV value. According to the library, when using function code 6, It get sending data(temperature value) from au16regs[0]as below piece of code of library file. Need to setup that value before requesting. (ModbusRtu.h - line number 601) case MB_FC_WRITE_REGISTER: //if cunction code 6 au8Buffer[ NB_HI ] = highByte(au16regs[0]); ...


2

Unfortunately the DFPlayer cant write that data to the SD card. The Arduino has some non volatile memory of its own built in though. Theres 1K of EEPROM for the UNO. Notes on how to use it here: https://www.arduino.cc/en/Reference/EEPROM If you can get what you need to done in 1K and its not important to your project that you be able to unplug the SD card ...


0

Use the constructor without parameter OneWire wire; and call wire.begin(pin); to set the pin. And to use more sensors on different pins, make the OneWire instance member of the DS28EC20 class.


1

I think Gerben is on to something. If you re-initialize the gps at every loop and then never give it time to acquire the gps signal then your if (GPS.fix) condition is never true and you never print out any other data. All your timing code is inside the GPS.fix condition which doesn't happen until you have a fix. Try putting the init code inside your ...


2

OK, time for my most comprehensive answer on StackExchange so far (tanks to @Juraj for helping out with this). To demonstrate all the steps needed for this, this answer will use an example library that will be called Foo. Here we go: To add documentation to your library that the Arduino IDE can work with, you first need to place your library in the ...


Top 50 recent answers are included