Go Down

Topic: HELP!!!! new to programming (Read 3206 times) previous topic - next topic


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!!! :)

keys needed:

Arrow up
arrow down
arrow left
arrow right


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 (http://arduino.cc/en/Reference/HomePage) 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.
Code: [Select]
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 :)


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.

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.
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts


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.


Jul 30, 2013, 04:10 am Last Edit: Jul 30, 2013, 10:17 am by AWOL Reason: 1
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:

Code: [Select]

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

void setup() {

 pinMode(upbutton, INPUT);
 pinMode(downbutton, INPUT);
void loop() {
 (digitalRead(upbutton)== HIGH); {
(digitalRead(upbutton)==LOW); {
(digitalRead(downbutton)== HIGH); {
   (digitalRead(downbutton)==LOW); {


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.


Code: [Select]
  (digitalRead(upbutton)== HIGH); {

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 post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics


Please don't follow the poor programming example provided by staressent above - it's a maintenance nightmare waiting to happen
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.


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

Go Up