Hi
my first post here....please I need help with arduino code that repeats a couple of button presses
it would be nice to have two or more buttons and LEDs
thanks
Boris
Hi
my first post here....please I need help with arduino code that repeats a couple of button presses
it would be nice to have two or more buttons and LEDs
thanks
Boris
Okay, so what have you tried? Code and schematic please. And please read How use the forum befor you post them ![]()
Sorry if this was posted incorrectly....will read rules. Thanks for answering me so fast.
I am total beginner....I have Arduino UNO and want to make device to repeat rithym given by pressing button...and than repeat it in loop.
I want to repeat a pattern of button presses - so that an LED will flash the same pattern afterwards...
This is what I have found online...no code just explained algorythm.
..........................................................................
declaire the inputs and outputs
is the button pressed
if yes count the time and store in a variable the count when the button is released
if no display the last recorded pattern
Display pattern
Turn on output for a count = to the stored value
turn off the output
check to see if button is pressed
go to the next variable and repeat display until last variable is reached.
repeat until button is pressed
.................................................................................
that is all .....just like on that YouTube video
thanks
B.
For starters, you could copy the code from the video ![]()
borislavgajic:
is the button pressed
That's not going to work, you want to save the time the buton became pressed which is something different ![]()
borislavgajic:
if no display the last recorded pattern
And define "no button pressed"?
And how many presses do you want to be able to count?
And with what resolution?
And you want to keep repeating the pattern, but how do you want to stitch the end to the beginning of the pattern? Aka, what time should be between them?
For starters, you could copy the code from the video ;)........ That was first thing I have tried but link is dead ![]()
5 presses to memorize in resolution of 500 ms....or something like that.
time between loops repeat 1000 ms.
something like TAP tempo but to be able to memorize 4 or 5 presses vith different time between them.
If you break the job down into parts that can co-operate through vatiables, it will be easier to code.
Buttons can be tricky once your code gets fast (can be fixed with a capacitor or in code) so usually best to have a button-handler that updates a button status variable, in void loop() and then the code to record time and button or led state and turn the led on and off. You will need to array the original button sequence and maybe a match sequence, are you up on arrays and indexes?
But I think you need more. How do you tell when to start and end recording a sequence and then when to start and end trying to match it?
Only having one button presents a challenge for sure! What are the full rules for your game? Until you know, don't get invested in a raft of code that will require hard changes to add whatever wasn't worked out ahead of time because that makes for massive code where simpler code would do. Make a working definition and then code to that, use definition lines as comments to guide in coding.
borislavgajic:
That was first thing I have tried but link is dead
Check again
Long live the Wayback machine ![]()
Rest is pretty easy to do ![]()
For buttons you need debounce and state change detection. If you want easy, grab a library like Bounce2.
Rest, just make an array for the times and time with millis().
GoForSmoke:
But I think you need more. How do you tell when to start and end recording a sequence and then when to start and end trying to match it?
That's what I meant with "define no button pressed". Easiest way is a time out ![]()
thank you very much for helping