Adding Buttons to META! Beginner Friendly!

Créations

Oasis

il y a 5 ans

For you advanced users just skip to the end where I will provide pictures, steps and maybe a video if I can

Why?

You may ask, why add buttons to the META? So here are my reasons:

  • Some future games may support them.
  • If you plan on using the META as a controller extra buttons are super useful - my Keybuino plans to support buttons very soon!
  • Some games may feel nicer to play with them e.g. Super Crate Buino with R to shoot - adding support will only take a few lines of code!
  • Its easy and cheap! Buttons are very cheap then you just need some wires! No resistors are needed (I believe the META has internal resistors - stay tuned)
  • It isn't necessarily permanent, can unplug them if you want.

Convinced? Let's go!

Theory

The Gamebuino, like any Arduino has pins.

Here's a nice diagram.

 Image result for gamebuino meta

This diagram corresponds to the back of the Gamebuino.

Adding buttons is as simple as connecting one end of the wire to ground and the other end to one of the pins 3-12 (To be safe don't use 13 as it isn't usually used for buttons due to complexities)

Compatibility?

Basically any button, 2 pin ones are better as they are less confusing:

Gikfun 12mm 250V 3A Push Button Switch PBS-11B No Self-Lock ON/OFF Lock for Arduino (Pack of 10pcs) AE1122

https://www.amazon.co.uk/Gikfun-Button-PBS-11B-Self-Lock-Arduino/dp/B01G3FCKXA/ref=sr_1_12?rps=1&ie=UTF8&qid=1550599422&sr=8-12&keywords=arduino+button&refinements=p_76%3A419158031

I'm not affiliated with these sellers

Despite this 4 pin buttons will work:

Cylewet 25Pcs 12x12x7.3mm Momentary Tact Tactile Push Button Switch Touch Switch Micro Switch 4 Pins SMD PCB with Cap for Arduino (Pack of 25) CLW1009

https://www.amazon.co.uk/Cylewet-12x12x7-3mm-Momentary-Tactile-Arduino/dp/B06XF2MHCM/ref=sr_1_1_sspa?rps=1&ie=UTF8&qid=1550599495&sr=8-1-spons&keywords=arduino+button&refinements=p_76%3A419158031&psc=1

Just to clarify here is a diagram of a button - you must use the 2 pins that are next to each other - just ignore the others:

Image result for arduino button diagram

So you will be soldering A and C

OR B and D

Otherwise the button will be permanently "pressed"

Wires

They're wires! Buy em, recycle em, but if you buy them buy ones with male connectors:

Image result for arduino wires

We will snip off one end to attach the button and leave the other end to stick into the Gamebuinos pins - easy to put in, and stay in, but also easy to remove without damaging anything.

If you don't have any, normal wires will work, we will just solder connectors on the other side:

Image result for male pins

Now don't try soldering a paperclip or something to it its a BAD idea! Just buy the wires or connectors- they are unbelievably cheap and you will have spares for other projects.

Soldering?

This is a quick and easy project requiring hardly any soldering so it is good for beginners - it is simple so don't expect to come out as a SOLDERING MASTER!! For people who have soldered it's really easy so don't worry about that.

Not much soldering is needed so I wouldn't really buy a soldering iron just for this project - try doing it at school (yes I'm at school - but I do own a soldering iron), university labs, or steal/borrow/steal one off a friend.

LETS DO IT!

Actually no I need to wait for parts to come so like you will have to wait a few days. lol. I will do a major update when I have finished the tutorial so make sure you follow it!

Adding Support to Games

OK so while we wit for parts to come let's see what code we need to implement buttons - I will go over bare minimum and a few extra bits.

To begin I will try to establish something, some tests show pins 1,2 and 13 are weird or something (unless its just me correct me) so when coding : read this as we don't need a mess of pins for EVERY game!! EITHER tell the player what pins the buttons are on OR use pins 3 and 12. So when coding projects use pins 3 and 12!!

3 and 12! You hear me?

3 and 12!

OK now that's been established a basic script for an L and R button on pin 3 and 12. This will work on any button so when testing use this script (don't believe me? This is the setup I used when testing the script:

Yes that button is made out of tinfoil and paper. It is).

#include <Gamebuino-Meta.h> 

//my variable names are all over the place sorry

bool lpressed;//these will return TRUE if the button is pressed
bool rpressed;

int lPin = 3;//button pins 3 and 12!
int rPin = 12;

int lFrame = 0;//completely optional but can be used to check the release of a button gb.button style
int rFrame = 0;//called this as it checks for a button press in the previous frame

void setup() {

  gb.begin();//lets go!
  pinMode(lPin, INPUT_PULLUP);
  pinMode(rPin, INPUT_PULLUP);


}

void loop() {

while (!gb.update());//
gb.display.clear();

if(digitalRead(rPin) == LOW){
  rpressed = 1;//yes in actual fact the button will return LOW upon a press!
}
else{
  rpressed = 0;
}

if(digitalRead(lPin) == LOW){
  lpressed = 1;//de ja vu?
}
else{
  lpressed = 0;
}

if (rpressed) {
  if(rFrame == 0){//if L was not pressed in previous frame - same as gb.button.pressed bassically
    gb.sound.playTick();
    //put gb.button.pressed action here
  }
  //put gb.button.repeat(0) code here for example:
  gb.display.println("12 and 3!");

  rFrame = 1;//this is essential for the press
}


if (lpressed) {
  if(lFrame == 0){//if L was not pressed in previous frame - same as gb.button.pressed bassically
    gb.sound.playTick();
    //put gb.button.pressed action here
  }
  //put gb.button.repeat(0) code here for example:
  gb.display.println("3 and 12!");

  lFrame = 1;//this is essential for the press
}

if(!rpressed){
  if(rFrame == 1){
    rFrame = 0;
    //this is the same as gb.button.release 
  }
}

if(!lpressed){
  if(lFrame == 1){
    lFrame = 0;
    //this is the same as gb.button.release 
  }
}


}

Its quite rewarding when this works so stay tuned for PART 3 - the part where we actually do stuff!

Sorry for advertising but Keybuino supports extra buttons now so check it out for applications of extra buttons! 

https://gamebuino.com/creations/control-pc-with-gamebuino-meta-keybuino

Voir la création

makerSquirrel

NEW il y a 5 ans

cool start, I am looking forward to the rest! One of my next games could profit from an L and R button anyway...

Oasis

il y a 5 ans

of course remember to let people without them play the game :)

Oasis

NEW il y a 5 ans

makerSquirrel makerSquirrel

of course remember to let people without them play the game :)

makerSquirrel

NEW il y a 5 ans

Others will need to use combinations of buttons since there are not enough :P

Oasis

NEW il y a 5 ans

yeah thats what should happen - forget about quality seal though...

mike_j503

NEW il y a 5 ans

Jeez, I have been 'on the fence' about buying a nice soldering iron for myself again for years now.

Maybe now is the time finally?

Oasis

il y a 5 ans

They are very cheap, and I learnt how to solder in around 15 minutes. You can repair things and make cool things with META or other arduinos - its also very satisfying. Maybe try it out somehow first or talk to someone you know if they found it useful first but I think it is a very cool tool that really allows consumers to be producers.

jicehel

NEW il y a 5 ans

The thing to think is a good idea to attach the additional pad with buttons to the META. Of course, you can glue it but i hope a better solution.

Oasis

il y a 5 ans

TBH im thinking blu-tac... I will find a better solution later - most likely to do with velcro

Oasis

NEW il y a 5 ans

mike_j503 mike_j503

They are very cheap, and I learnt how to solder in around 15 minutes. You can repair things and make cool things with META or other arduinos - its also very satisfying. Maybe try it out somehow first or talk to someone you know if they found it useful first but I think it is a very cool tool that really allows consumers to be producers.

makerSquirrel

NEW il y a 5 ans

I will wait for the result of Oasis/Owais tutorial. If there is a commonly available button format and I know his final setup I can make a 3d model that should be compatible with it, so everyone can print it with a 3d printer. If there are many who want to have that, maybe Aurélien could add pre-printed versions to his shop. But first step-by-step with this tutorial ;)

Oasis

NEW il y a 5 ans

jicehel jicehel

TBH im thinking blu-tac... I will find a better solution later - most likely to do with velcro