![Using Using](/uploads/1/2/5/4/125465233/728098318.png)
Using and - with floating-point variables: Increment Decrement Operators « Operators « Java Tutorial. As long as the starting value, the decrement amount and the result of all the. However, I see no point in using floating point, when integral type is more reliable.
I suggest you to use debounce to detect if a pin has been definitely pressed. You could also test using interrupts (hint: interrupts can happen multiple times even if you 'only' pressed once). So either use Arduino's example of debounce or take a look at the found on their website.Now that you can check whether or not either button A or B has been pressed, how do you keep track of the voltage to be output? You should use a counter variable that will be incremented when button A is pressed and decremented when button B is pressed. Here is a pseudocode: if(ButtonA pressed)counter;else if(ButtonB pressed)counter-;This counter variable can be used to control the output voltage. Remember that the argument for analogWrite function on the Arduino Uno is the duty cycle which takes in values from 0 to 255. So analogWrite(0) ≣ 0 Volt and analogWrite(255) ≣ 5 Volt.
![Increment Increment](/uploads/1/2/5/4/125465233/345331457.png)
So at the moment, you couldn't just do analogWrite(counter) because you would need to press 255 times button A!Instead, you would need a way to convert your counter to reflect the increment you need. You mentioned that it should require 10 presses to reach 5 Volt at the Arduino output, and the easiest way to accomplish this is to use Arduino's. The pseudocode would look like this: Output = map(counter, 0, 10, 0, 255);analogWrite(Output);Now there is one last step! The map function will limit the output voltage from 0 to 5 Volt so everything will be safe; however, the counter is not limited to 0 to 10. This means that even if the counter is at 15 (because you pressed button A too many times) the voltage will be 5 Volt and you would need to press button B at least 6 times to see the voltage go down! So to limit the counter you could easily implement your own function: if(counter = 10)counter = 10;else if (counter.