I'm building a reaction game using Arduino Nano and i'm looking for a way to increase the speed of my LED's changing colour. For now im using int but this method only allows me to use full numbers (1,2,3,4,5,6 etc.) but now im looking for a way to use numbers with comas instead (1,5/5,5 etc.) is there a way to do so?
Hello panic_rider41
We need some additional information.
Post your sketch, well formated, with well-tempered comments and in so called code tags "< code >" and a real schematic to see how we can help.
Have a nice day and enjoy coding in C++.
Just use larger integers, and scale them.
Of course, that's just a guess, based on the absence of any facts
(What are the "comas" used for?)
Computers and programs use the decimal point (.) to indicate fractions, rather than the comma. Those values are called float - short for "floating point"... what features will your project have? Have you drawn a picture of your idea?
Decimal separator in some parts of the world. Commas.
Oh, time seems to be going backwards on my tablet. Never mind.
a7
Here for example.
That period (full-stop) is used as a sentence terminator.
The decimal separator can be either a full stop, or a comma depending on what country you are from. Details are here.
Looking at the list of countries, it appears that there are roughly the same number of countries using a comma as there are using the full stop.
Computer programming languages tend to use the full stop as they use keywords derived from the English language.
... and the comma separates/delimits fields, for example (1, 2, 3, 4, 5) as @panic_rider41 showed (in standard, English-language based computer program writing)....
So... the features that @panic_rider41 probably wants to include are fractional movement between whole numbers, that is to say, from "1" to "2" ... 1.1, 1.2, 1.3, et c.
If you are timing using delay() or millis(), then you have to use "whole numbers" (unsigned int).
You can get smaller time intervals using micros() or delayMicroseconds().
A microsecond is 1/1000th of a millisecond
but you still need to use "whole numbers" of microseconds.
If you wanted a delay of say 1,5/1.5 milliseconds, you could multiply by 1000 and use 1500 microseconds instead.
If you are looking for speed, then you really want to avoid using floating point numbers if at all possible. Handling floating point numbers is generally difficult for a computer, with the result that they get handled much more slowly than integers, and require much more code space for the program as well.
What you can do is called scaling. Multiply all of your numbers by some scaling factor, like say 100. This means that 1,0 becomes 100, 1,5 becomes 150 and so on. Use the numbers like that everywhere in your program, and only translate them back to fractions if you need to print them out.
Also called fixed point math:
If, rather than decimal digits, you scale in a number of bits, it is Q format:
Do you have tried any of code
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.