hello i am a beginner with arduino programming. can someone help me with the code where i can make the blink rate of LED to increase or decrease by using two push buttons? the first button is to make the LED blink faster, and the second one to make the LED blink slower.
Hello cerberus03
It seems to be a school assigment, isn´t it?
Post your sketch, well formated, with comments and in so called code tags "</>" and schematic to see how we can help.
Have a nice day and enjoy coding in C++.
First this is a case where you really have to use a blink without delay approach, so have you at least got the standard bwod code loaded and running?
(If you don't use that approach, the buttons will be very unresponsive.)
Then add two buttons and when either is pressed, use interval++ and interval-- respectively to adjust the rate.
how do i use the interval++ and interval--?
It's just a shortcut command- you don't have to use it. It's explained on the Arduino reference pages.
It's the same as saying:
interval = interval + 1
// or
interval = interval - 1
Have you worked through the examples?
Hello
Genearly spoken the sketch needs two timers. One timer to blink the LED and the other one to read the up- and down button either to increment or decrement the time for the blink interval.
The BLINKWITHOUTDELAY example of the IDE is perfect base to start. Take a view.
Have a nice day and enjoy coding in C++.
should i use a for() statement to indicate the blink interval? if it's not possible, what should i use instead?
Not sure what that means, sorry.
But in the Blink Without Delay sketch (I asked earlier if you are using that one or similar....) the variable interval is already there. If you do an interval++ or -- then the rate should change.
Difficult to help if you don't show what you're doing in the code so far.
That code already has a variable called interval; I'd start just by doing a ++ with one button and a -- with the other.
how do i do that? should i remove this?
what I want is, the blinking rate to gradually increase or decrease throughout the program e.g it begins at say 250 milliseconds then ends up being 1000 and vice versa