Any Arduino gurus here - Pls help?

kombi-man

Well-Known Member
Joined
Mar 14, 2017
Messages
486
if anyone here is an Arduino guru, please can you help me.. I'm not.

I have a working Arduino Micro board which has 32 buttons connected to it, and which works 100%. I need to add a little piece of code to the bottom of the existing "sketch" I think it's called, which forces a specific button to emulate pressing the "TAB" key, specifically.

I found this online. Bit if I load this, and then inspect it, it just give me the middle finger?

PS. I do NOT have a clue when it comes to programming or anything of this nature..

void setup() {
// make pin 2 an input and turn on the
// pullup resistor so it goes high unless
// connected to ground:
pinMode(2, INPUT_PULLUP);
Keyboard.begin();
}
void loop() {
//if the button is pressed
if(digitalRead(2)==LOW){
//Send an ASCII 'A',
Keyboard.write(65);
}
}

So, for my requirements, I understand we replace the '65' with '09' to replace the A with the TAB, but, also, on my wiring diagram of this switch box, I have an array of buttons wired across the pins, eg: A0 and 10, is the button I'd like this "code" above to work with. But, I can't even get the code to look right.

Please can you help?

regards

Alan
 

kombi-man

Well-Known Member
Joined
Mar 14, 2017
Messages
486
Eish, I am not sure to be honest.. Lets wait if someone can give me the proper code to make this function.
 

Gnome

Executive Member
Joined
Sep 19, 2005
Messages
7,208
tab is '\t'
newline is '\n' in POSIX and "\r\n" on Windows
 

gregmcc

Honorary Master
Joined
Jun 29, 2006
Messages
25,513
How is the hardware wired up to the Arduino. Can you post a link to the existing .ino file?

> pinMode(2, INPUT_PULLUP);

This will set data pin to a input and turn on the internl pullup resistor. (So if your push button does not have any pullup resistors you can use this)

>Keyboard.write(65);

What library are you using? This would write a 65 decimal somewhere. Depending on what keyboard routine does.

Update: Actually have a look here. You must be using a usb keyboard connected to the Arduino. You will need to use keyboard modifiers for special keys:

https://www.arduino.cc/en/Reference/KeyboardModifiers
 
Last edited:
Top