Ifs and loops

 if (button.available())

This is Timer, i enter the name of timer in global variables,then in setup I specify what is the time in milliseconds for the timer. In the code itself I can use this in many ways, it's a good replacement for delay because it does not block anything. In the code I ask if the time has passed 700ms if yes it do that part of the program, reset the timer. If I remember well, I can have up to 8 timers.

Timer program;
Timer button;
void setup(){
Serial.begin(9600);
TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM01) | _BV(WGM00);

Whitespaceisagoodthing.

You have not posted your whole program but it sounds to me as though using a Timer object named button is not contributing anything to your program apart from confusion.

It seems to me that you should get the value from analogRead(0) as often as possible and determine whether it has changed significantly since the last time it was read. If so then use its current value to determine the action to be taken.

As a matter of interest, why is the pin variable (terrible name !) declared as a float because analogRead() does not return a float

UKHeliBob:
As a matter of interest, why is the pin variable (terrible name !) declared as a float because analogRead() does not return a float

What does it mean? I store a value of 0-1023 in the float function named pin and everything works. I do not understand what you mean, please write it simple so i could understand. I used the int function once in code and the maximum value I could store was 327 if I remember correctly, then I used float and everything worked.

Patryk20:
I used the int function once in code and the maximum value I could store was 327 if I remember correctly, then I used float and everything worked.

Did you possibly mean 32767?

I think you need to start paying attention. You are "shotgun programming"... close your eyes and shoot the gun, eventually some pellets will hit the barn.

I store a value of 0-1023 in the float function named pin and everything works.

There is NOT a float function. Float is a data type. It does not make sense to use a float data type to store integer values.

The name of the variable is misleading at best. It does NOT store a pin or a pin number. It stores a value.

int pinValue = analogRead(pinNumber);

Now, it is perfectly obvious which variable contains a pin number and which contains the value read from the pin. And, it is perfectly obvious that the value is an integral value (a whole number).

aarg:
Did you possibly mean 32767?

No, i mean 327, but i cannot go back to this part of program when it was working like this.
So its better to store values in int from sensor readings. But can i store something like this 3,45 in int? I was thinking that i could store only full numbers like 3. When its better to use float? (example would be good to understand) :slight_smile:

But can i store something like this 3,45 in int?

No, but you can't get 3,45 from analogRead(), either.

When it`s better to use float?

When you are trying to measure how much liquid is in a tank, a float is a good thing to use.

UKHeliBob:
It seems to me that you should get the value from analogRead(0) as often as possible and determine whether it has changed significantly since the last time it was read. If so then use its current value to determine the action to be taken.

Thank you very mutch for this advice +karma :slight_smile: Now it`s working perfectly!

PaulS:
When you are trying to measure how much liquid is in a tank, a float is a good thing to use.

This is the worst example ive have seen in my life haha, didnt understand at all my friend.

Now it`s working perfectly!

I would be interested in seeing the working version as there may be further enhancements that could be made.