void setup() {
Keyboard.begin(); //Start the keyboard simulation
//
}
void loop() {
Look at this, i want that "B" be press every 3 seconds, but it gets pressed every 8 seconds, because "B" has to wait 5 seconds that "A" be pressed.
I want that "A" be press every 5 seconds and "B" every 3 seconds, separated.
So, get rid of the delays.
Look at the blink without delay example for clues.
What has this got to do with installation of the IDE?
royalarchers:
Look at this
I see that you posted in the wrong category and didn't post your entire sketch, or post with code tags. Please read here to learn how to fix those issues with your post:
See also FAQ - Arduino Forum for general rules on forum behaviour and etiquette.
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…
What is the greatest common factor of 3 and 5? It's 1. So make your delay one second and
Pseudocode
repeat
{
if A >= 5
{
A = 0
send key A
}
if B >= 3
{
B = 0
send key B
}
delay 1 second
}
Spice and flavour to suit...
1 Like
@royalarchers
Your topic was moved to its current location as it is more suitable.
Could you also take a few moments to Learn How To Use The Forum .
It will help you get the best out of the forum in the future.
Thank you
Thank you Perry,
i edit and post the entire sketch.
I cant get rid of the delays because i need them.
I need some key be press every couting time, but i need those keys respect those times.
But without code tags. That is why you need to actually read what you are asked to read.
b707
January 20, 2023, 9:55pm
9
You didn't understand.
You need to get rid of not delays as "time intervals", but the delay() operators.
This is a blocking statement, it stops all other processes in the controller. As long as you use it in the program, you will not be able to get independent execution of two sequences
Um, not quite. OP can only get into trouble if additional tasks must run more than once per second, with my pseudocode.
1 Like
b707
January 20, 2023, 10:00pm
11
This is not a general solution, but a particular one
It's someones first day at the keyboard. Let's let them go one step at a time.
1 Like
void loop() {
//attack
static unsigned long lastATime = 0;
if (millis() - lastATime >= 5000)
{
lastATime += 5000;
Keyboard.press('A');
Keyboard.release('A');
}
//next target
static unsigned long lastBTime = 0;
if (millis() - lastBTime >= 3000)
{
lastBTime += 3000;
Keyboard.press('B');
Keyboard.release('B');
}
}
red_car
January 21, 2023, 12:52am
14
anon57585045:
Pseudocode
Might want to increment A & B each loop... ?
Man, you gave it away. I wasn't going to reveal that until the end. Notice I also didn't release the keys.
Do you ever wonder, hey, what did the OP finally do? ?
Kind of like, goodbye, and thanks for all the fish.
system
Closed
July 20, 2023, 1:36pm
16
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.