HELP!!!! new to programming

Ive got a project goin that needs me to have 6 pushbuttons wired to the arduino micro, I need help programming the sketch to make those 6 buttons to type a specific key (keys are listed below). Any help would be appreciated!!! :slight_smile:

keys needed:

Arrow up
arrow down
arrow left
arrow right
enter
Backspace

You need to say what sort of arduino you have.
Simulating keys is easy on some types and difficult on others.

I apologize now if my answer provides no help but this is the best I can do, if you don't like it ignore it.

Were not going to do the coding for you, (at least I'm not) because then you'd never learn.
One option would be to check out some of the examples for the Arduino (you can find the ones best for your case in File>Examples>Basics).
but better than that would be to study the language, start with the basics on the Arduino page (Arduino - Home) and/or find yourself a good C or C++ textbook or refrence web site (C++ preferably) and start studying it. I won't promise it to be exciting but then this is education, you get out what you put in.

lastly just so you don't think I'm no help at all this is the general format I use for multiple buttons.

void setup() {
  pinMode(14, INPUT);  //enter
  pinMode(15, INPUT);  //up
  pinMode(16, INPUT);  //down
  pinMode(17, INPUT);  //left
  pinMode(18, INPUT);  //right
  //other setup code...
}

void loop() {
  while(!digitalRead(14)) {
    if(digitalRead(15)) first_function();
    if(digitalRead(16)) second_function();
    if(digitalRead(17)) third_function();
    if(digitalRead(18)) fourth_function();
  }
}

Thanks guys! I wasnt expecting anyone to do it for me, just some steps to get me goin... ive been bangin my head on this for a little while. Thanks again for the fast respones, and to Grumpy mike I have an arduino micro :slight_smile:

It would really help you to go through a number of examples you can find in your Arduino IDE. Learn to trace code line by line while picking up the language fundamental basics.

If you learn all of the Control Structures tutorials and Nick Gammon's tutorial linked below you should know enough to start off well.

The examples are also covered with more explanation on the Arduino site. Here are some links to bookmark, collect more as you go.

Arduino specific pages, the last is the reference for the standard libraries that Arduino uses.

http://www.nongnu.org/avr-libc/user-manual/modules.html

This tutorial is maybe the most important you can learn to get started on real time code.

Here are two C/C++ tutorial sites, but more oriented to PC's than microcontrollers.

programming the Arduino as HID USB keyboard
http://forum.arduino.cc/index.php?topic=178810.0
http://forum.arduino.cc/index.php?topic=116644.0

Awesome! Thanks so much, Ill do my best to learn the language, thanks again!!!

The micro is the same classof arduino as the Leonardo so it is easy to do. Look for Leonardo examples.

i am a complete beginner at this, this is my first real sketch so i really need some guidance.
all i am wanting to do is wire 6 push buttons to the ARDUINO MICRO and make them push keys on the keyboard,up,down,left,right,enter,and backspace. so far i have gotten 2 pushbuttons in the sketch...if someone can help i can definatly do the rest of em
Heres the Sketch:

const int upbutton = 4; 
const int downbutton = 6;

void setup() {
 
  pinMode(upbutton, INPUT);
  pinMode(downbutton, INPUT);
  Keyboard.begin();
}
void loop() {
  (digitalRead(upbutton)== HIGH); {
    Keyboard.press(KEY_UP_ARROW);
    delay(150);
}
(digitalRead(upbutton)==LOW); {
  Keyboard.release(upbutton);
 }
(digitalRead(downbutton)== HIGH); {
    Keyboard.press(KEY_DOWN_ARROW);
    delay(150);
}
    (digitalRead(downbutton)==LOW); {
  Keyboard.release(downbutton);
 }

  
 }

its messy i know, but its my first one.....
what i need help with is when i upload the sketch it continually presses the 2 buttons at the same time, and also how would i wire this?
i know i am asking for a lot but ANY help would be awesome!
oh and im not asking someone to write the code for me i just want some help thats all

Moderator edit: CODE TAGS AGAIN.

  (digitalRead(upbutton)== HIGH); {
    Keyboard.press(KEY_UP_ARROW);
    delay(150);
}

Looks like you're missing some if statements, else statements and have some erroneous semicolons. I recommend looking at some simple examples on how to structure if statements with regards to semicolons, brackets, etc.

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

  • Moderator

Please don't follow the poor programming example provided by staressent above - it's a maintenance nightmare waiting to happen

Okay I feel like Ive got everything workin on the software side, how would I wire it up? Sorry im pretty much clueless on how to do this but im ready to learn!

Your buttons are simulating keyboard cursor controls in an OS application.... Like a USB keyboard. All of the wiring is virtual----> over the USB cable.
Open notepad, word or similar, the plug in your Arduino... Give plug 'n play a few seconds, have fun. Remember, the Arduino thinks it is a keyboard.

So how would I use pushbuttons with the arduino micro?, if its all virtual

Apologies ... I assumed you were talking about the PC end.

Your buttons go to pins on the Arduino that are defined in statements like this

void setup() {
  pinMode(14, INPUT);  //enter
  pinMode(15, INPUT);  //up
  pinMode(16, INPUT);  //down
  pinMode(17, INPUT);  //left
  pinMode(18, INPUT);  //right
  //other setup code...
}

The 14 - 18 are Arduino pins NOT physical numbers.

Buttons are wired: http://arduino.cc/en/Tutorial/Button

mrburnette:
Apologies ... I assumed you were talking about the PC end.

Your buttons go to pins on the Arduino that are defined in statements like this

void setup() {

pinMode(14, INPUT);  //enter
 pinMode(15, INPUT);  //up
 pinMode(16, INPUT);  //down
 pinMode(17, INPUT);  //left
 pinMode(18, INPUT);  //right
 //other setup code...
}




The 14 - 18 are Arduino pins NOT physical numbers.

Buttons are wired: http://arduino.cc/en/Tutorial/Button

And you really want to look at some of the Debounce code options to ensure you are getting what you think you are getting from each of the buttons.

Have a look in the examples under digital for Button and Debounce

Craig

mrburnette:
Apologies ... I assumed you were talking about the PC end.

Your buttons go to pins on the Arduino that are defined in statements like this

void setup() {

pinMode(14, INPUT);  //enter
  pinMode(15, INPUT);  //up
  pinMode(16, INPUT);  //down
  pinMode(17, INPUT);  //left
  pinMode(18, INPUT);  //right
  //other setup code...
}




The 14 - 18 are Arduino pins NOT physical numbers.

Buttons are wired: http://arduino.cc/en/Tutorial/Button

One reason to learn the Control Examples in the IDE before writing your own code is to learn about arrays and for-loops.

#define KEYS 5;
byte keyPin[ KEYS ] = { 14, 15, 16, 17, 18 }; // easy to change once here, easy to use below
enum { enter, up, down, left, right } key; // learn about these later, just be aware

void setup() {
  for ( byte i = 0; i < KEYS; i++ ) // i will not exist outside of this for loop
  {
    pinMode( keyPin[ i ], INPUT );   
  }
  //other setup code...
}