Convert a String to a byte array and then back to the original String

I would suggest using the members of string, but with an explicit encoding: byte[] bytes = text.getBytes(“UTF-8”); String text = new String(bytes, “UTF-8”); By using an explicit encoding (and one which supports all of Unicode) you avoid the problems of just calling text.getBytes() etc: You’re explicitly using a specific encoding, so you know which encoding … Read more

vscode “#include errors detected. Please update your includePath

Although the question mentions Arduino, the following suggestions apply basically any time VSCode tells you to “update your includePath”. What is includePath? The includePath is an attribute in c_cpp_settings.json, which is in the .vscode folder of the main folder you have opened in VSCode using File → Open Folder. You can edit c_cpp_settings.json directly, but … Read more

Reversible pseudo-random sequence generator

I asked a very similar question at the tigsource forums. Hashing At least in games, a hash function could probably do what you want. You could do it like this class ReversibleRNG { int x; public: ReversibleRNG(int seed) : x(seed) {} int next(){return yourFavoriteHash(++x);} int prev(){return yourFavoriteHash(–x);} }; Reversible linear congruential generator (lcg) As multiple … Read more

Mapping a numeric range onto another

Let’s forget the math and try to solve this intuitively. First, if we want to map input numbers in the range [0, x] to output range [0, y], we just need to scale by an appropriate amount. 0 goes to 0, x goes to y, and a number t will go to (y/x)*t. So, let’s … Read more

Load cell Arduino HX711 Fluctuating up

I recently bought some extremely cheap (5 for $10.00) HX 711 boards. I noticed the same thing that you did; value drifting upward. I checked the on board load cell power supply and it seems to be defective. The band gap reference voltage (VBG) which is supposed to be 1.25 volts is actually 1.9 volts, … Read more