Go Down

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

ballow70

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
enter
Backspace

Grumpy_Mike

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

staressent

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();
  }
}

ballow70

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

GoForSmoke

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://arduino.cc/en/Tutorial/Foundations
http://arduino.cc/en/Tutorial/HomePage
http://arduino.cc/en/Reference/HomePage
http://arduino.cc/en/Reference/Libraries
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.
http://www.gammon.com.au/forum/?id=11411

Here are two C/C++ tutorial sites, but more oriented to PC's than microcontrollers.
http://www.tutorialspoint.com/cprogramming/index.htm
http://www.cprogramming.com/tutorial/c-tutorial.html
http://www.cprogramming.com/tutorial/c++-tutorial.html
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts


ballow70

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

Grumpy_Mike

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

ballow70

#8
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);
 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.

Arrch

Code: [Select]
  (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.

Nick Gammon

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

AWOL

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.

ballow70

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!

mrburnette

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.

ballow70

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

Go Up