#include <Keyboard.h>
#include <Mouse.h>
const int inputPin = 11;
int butondeger = 0;
int randomNumber;
void setup() {
Keyboard.begin();
Mouse.begin();
pinMode(inputPin, INPUT);}
void loop(){
butondeger = digitalRead(inputPin);
if (butondeger != HIGH) {
butondeger = digitalRead(inputPin);
Keyboard.press('4');
delay(150);
Keyboard.release('4');
delay(25);
delay(800); }
else { Keyboard.releaseAll(); }
Keyboard.end();
if (butondeger != HIGH) {
butondeger = digitalRead(inputPin);
Keyboard.press('5');
delay(150);
Keyboard.release('5');
delay(25);
delay(800); }
else { Keyboard.releaseAll(); }
Keyboard.end();
if (butondeger != HIGH) {
butondeger = digitalRead(inputPin);
Keyboard.press('6');
delay(150);
Keyboard.release('6');
delay(25);
delay(800); }
else { Keyboard.releaseAll(); }
Keyboard.end();
}
Hello Friends, I am new to Arduino.
I couldn't figure out where I am making a mistake. I would be very grateful if you could help me.
When I hold the button, it presses 4 5 6 respectively, there is no problem here, but when I press and pull the button, I want it to press only 4, but it presses 4 and 5.
Thank you very much in advance for your help
PaulRB
April 12, 2024, 10:25am
2
Please read the forum guide in the sticky post to find out how to post code correctly on the forum. Then edit and correct your post.
1 Like
PaulRB
April 12, 2024, 10:26am
3
Your code needs to read the button pin again before sending the next key.
1 Like
I'm very sorry, this is my first time opening a topic because my English is inadequate. If I disturb you, you can close the topic. I use google translation.
PaulRB
April 12, 2024, 10:28am
5
What languages are you comfortable using? There are forum sections for several different languages.
1 Like
I tried to do something by compiling the codes from different pages.I don't have enough Arduino knowledge
How can I make the code I wrote read the button pin again before sending the next key? Can you please write me an example code?
2112
April 12, 2024, 10:39am
9
Walk through the below code. What is it doing?
What state is butondeger?
1 Like
2112:
butondeger
butondeger is buttonstate sory my English is not good
Post your entire sketch.
Use the IDE Autoformat tool.
Use the IDE Copt for Forum tool.
Come back here and paste it ina new post on this thread.
Or, you can use the <CODE/> tool in the message composition window and paste where it tells you to
type or paste code here
so your code looks like code
void setup() {
}
void loop() {
}
Also, how is your button wired? Are you using a pull-up or pulldown resistor? Do you know about INPUT_PULLUP for use in pinMode ()?
a7
1 Like
2112
April 12, 2024, 10:44am
12
Is butondeger HIGH or !HIGH when you get there after a button press?
1 Like
I couldn't manage to send you the code, I can copy and paste it in the reply tab.
Try again. All the code should end up in a code section
// that looks like this
void setup() {
}
a7
1 Like
#include <Keyboard.h>
#include <Mouse.h>
const int inputPin = 11;
int butondeger = 0;
int randomNumber;
void setup() {
Keyboard.begin();
Mouse.begin();
pinMode(inputPin, INPUT);}
void loop(){
butondeger = digitalRead(inputPin);
if (butondeger != HIGH) {
butondeger = digitalRead(inputPin);
Keyboard.press('4');
delay(150);
Keyboard.release('4');
delay(25);
delay(800); }
else { Keyboard.releaseAll(); }
Keyboard.end();
if (butondeger != HIGH) {
butondeger = digitalRead(inputPin);
Keyboard.press('5');
delay(150);
Keyboard.release('5');
delay(25);
delay(800); }
else { Keyboard.releaseAll(); }
Keyboard.end();
if (butondeger != HIGH) {
butondeger = digitalRead(inputPin);
Keyboard.press('6');
delay(150);
Keyboard.release('6');
delay(25);
delay(800); }
else { Keyboard.releaseAll(); }
Keyboard.end();
}
I'm sorry, this is my first time using a forum, I'm a novice.
I learned how to send correct code thank you
1 Like
coldfire35:
I'm a novice.
That's OK, we all started knowing nothing. I did, anyway.
Now we can see your sketch properly, thanks.
Please say how you have connected the button to the Arduino. Are you using a resistor?
When you read our responses, try to see the questions we ask.
Put your finger on the code and step it through line by line, pretending to be the dumb computer. Your sketch is doing exactly what you wrote, not what you think you wrote.
Until you add the keyboard sending part, leave that out and use the serial monitor to print things where you will later send a key press:
if (butondeger != HIGH) {
butondeger = digitalRead(inputPin);
Serial.println("pressing 5");
delay(150);
Serial.println(" releasing 5");
delay(25);
delay(800); }
else { }
When you get the printed information correct, change it back to keyboard calls.
HTH
a7
1 Like
i use 10k ohm resistor to GND and I connected to the foot pedal, pin 11 5v to power
Look here about the serial monitor. You need to know how to use it, or you will soon:
https://arduinotogo.com/2017/02/28/chapter-6-using-the-serial-monitor/
a7
1 Like