Hi. I'm new to arduino and have just written my first simple program with YouTube help and other for blower controll.
Now I have problem with pushbuttons.
If I press first one (left) - temp. goes UP, but in the code it must go DOWN. (buttonPin1)
If I press second (right) - temp. goes DOWN in the code must go UP. (buttonPin2)
Please post your whole program and use code tags when you do by using the icon on the left above the editor.
You appear to be using a debounce library but ignore what it returns. How are your pushbuttons wired ? With the code as it is what do you expect to happen if one of the buttons is held down ?
pinMode(buttonPin1, INPUT_PULLUP); //tipka 1 je temp. DOL
Why have you got resistors wired to the buttons when you use the internal pullup resistors
void TempUp()
{
int value2 = debouncer2.read(); //read a debounced input
value2 = digitalRead(buttonPin2); //overwrite the value just read
if (value2 == HIGH) { //if the button is not pressed - remember the INPUT_PULLUP ?
delay(500); //waste some time
value2 = digitalRead(buttonPin2); //read the value again
if (value2 == HIGH) { //if the button is still not pressed
a = a + 1; //add 1 to the variable
}
}
}
These functions are nonsense.
It is impossible to tell how your buttons are wired from your picture. Are the input pins takem HIGH or LOW when the button is pressed and are they normally held HIGH or LOW ?
Wire the buttons so that they take the input pins LOW when pressed. Remove the resistor and other wiring to the buttons. Now the pin will be normally held HIGH and will go LOW when pressed.
Change your functions
void TempUp()
{
int value2 = digitalRead(buttonPin2);
if (value2 == LOW) //button is pressed
{
a = a + 1;
}
}
This will still not do what you want because the counter will be incremented when the button is pressed and what you really need is to detect when it becomes pressed but try it anyway. You can add the state change detection and debouncing later.
int value2 = digitalRead(buttonPin2);
if (value2 == LOW) //button is pressed
How about some useful names, like upPin and upState, downPin and downState? You see a name like buttonPin2 and all that you know is that it contains the number of a pin that a button is sewn onto. There is NOTHING that assigns a meaning to that "button". upPin contains a pin number, and the meaning of the switch is obvious.