New answers tagged

1

Comparing floating point values is notoriously difficult. This is because floating point is only an approximation. You should first define an error margin - a value which is how close together the two values need to be before you consider them to be the same. For example 1.000000 and 1.000001 could be considered to be the same value in many circumstances. ...


1

If you plan to continuously take data at a fixed rate, I suggest you don't timestamp the individual records. Instead, store the initial timestamp and the data sampling period in a binary header, followed by fixed-size binary records. Then, when you want to retrieve the record for time t, you can fseek() right to uint32_t offset = header_size ...


0

Create a single file (SD logger?) When data is received from a sensor, store it in the file, and store this information: Date/Time stamp Which sensor Sensor data When a request for data is received (probably containing start and end time stamps, parse through the file, and start returning information for those date/time stamps within the requested start/...


0

Have a look at some code inside the forum from marcello.romani. He posted it on jan 1st, 2013. The topic on subject is called : "button pressed more than 2 seconds do somethingelse" Marcello's code is so KISS (Keep It Simple Stupid) and efficient that it deserves a Nobel prize. The goals is to handle the different signals that come from a button or ...


0

What you want for this project is called a ring buffer. Before reading the rest of this answer, I suggest you stop and take the time to carefully read the Wikipedia page I am linking to. Did you read it? Good! Now, yours is a somewhat special case in that you don't need to continuously keep track of both a read pointer and a write pointer: you only need the ...


0

Your code doesn't make much sense as written. You need to: Collect a new value every 30 seconds and save it into an array of values, incrementing a "current value index" variable with each read. Do you want to trigger the sending of a buffer-full of data when the array is full, or using a command from the remote phone? If you want to trigger the sending ...


0

Here is a program that should fade the LED as you specified. Initially the LED is off. If you press the button the LED starts fading within the time frame to its maximum. Then it switches to zero waits a couple of seconds and starts fading from new. If you press the button a second time the LED stops fading and is set to darkness. ;-) This happens emediately,...


0

If you would to write more professional code, you could try to use a different editor instead the basic arduino editor. Possible choices are, for example: Visual Studio Core with platformio plugin. Eclipse With Sloeber plugin. Since arduino already use C/C++ Languange, the only difference is the way you write and organize the code.


0

Arduinos use a standard C++ compiler. The supposed "Arduino Language" doesn't exist; it is C++. Except that the Arduino IDE will permit you some shortcuts that the compiler doesn't. The two biggies are: The IDE will notice that your are trying to use libraries (ones it recognizes, anyway) and insert the necessary #include <SOMELIBRARY.H>, if you didn'...


0

Your code is so badly formatted it makes it very difficult to follow. A couple of things that jump out at me: You never set REED_PIN1 or REED_PIN2 to INPUT_PULLUP mode. You should do that in setup. You have the code that deals with REED_PIN2 commented out so that can't possibly work. I took a first crack at improved code formatting. There result is ...


0

Sorry, but your code is complete nonsense. The following code gives you an example. I have no access to a compiler at the moment, so there might be syntax errors and it is completely untested. Also, you gave no complete description of the things you want to do. e.g when to switch on the green LED or what the up and down variables are for. And there might ...


3

The inline modifier doesn't make a sense for methods definitions in separate cpp file. And obviously it makes the code compilable but methods aren't recognized as methods definitions and also it's not recognized as error (that's kinda weird). Anyway, if you wan't inline methods, do it directly inside of class definition.


1

See Guide to PROGMEM on ESP8266 and Arduino IDE. Since you put your char array into PROGMEM, special functions must be used to load it from flash into RAM; so to load it into a String object, the FlashHelper class must be used. You can simply use the macro FPSTR(progmem_ptr). #include <Arduino.h> void setup() { Serial.begin(115200); Serial....


2

This construct does work in Arduino IDE. In fact, = { 0 } is one of the iconic idioms of C language. It can be used to zero-initialize an object of any type in C. In C++ things are a bit more complicated. It will work for an int [100] array, but in general case you might be better off with = {} initializer to achieve the same effect where applicable. It is ...


1

You can use any C++ IDE you like, best when bundled with a compiler, for example Code::Blocks. Assuming you're using Windows: A combination of a decent editor like Notepad++ and some good compiler chain like MinGW will do, too. If you absolutely have to you could also use MS Visual Studio, I don't bother. Then create standard console programs with this main(...


1

You would be better off formatting it nicely instead of relying on String... char macValue[17]; // Don't forget one byte for the terminating NULL... uint64_t mac = ESP.getEFuseMac(); sprintf(macValue, "%016x", mac); client.publish("esp32/ChipID", macValue); However, I'm not certain that sprintf can cope with a 64 bit value like that directly. If not, you ...


0

In late 2019 we have the Deviot Sublime Text 3 plugin that runs on top of PlatformIO.


Top 50 recent answers are included