The way the buttons are handled in the example is actually pretty common on simpler platforms like the NES and Game Boy. You could code a nice shorthand like that yourself, but every extra step like that, both in written code and time to execute, is going to add up on a low power platform like this. The more ārawā youāre willing to do it, the better, Iād say.
If you want to make it look nicer, you could probably do something like this (not sure if the code will work perfectly as written without testing it, Iām rusty):
//in declarations at the top
#define B_BUTTON 1
#define A_BUTTON 2
#define DOWN 4
#define RIGHT 8
#define UP 16
#define LEFT 32
void loop() {
uint8t buttons = display.getInput();
if(buttons & LEFT) {
display.print("Pressing Left!");
}
//etc.
}
buttons contains a single byte consisting of the current state of all the buttons. Left on the d-pad is represented by the 6th bit from the right, which seen in binary is b00100000 which is 32, which is why LEFT is defined as 32. Doing a logical AND between buttons and LEFT checks whether buttons contains a 1 in the sixth āslot,ā to see if left is being pressed.
I tried your code on the Dev kit.
Started new Arduino sketch, put the declarations in the void Setup() function. Put the test in the normal void loop() function. So my final code ended up looking like:
void setup() {
#define B_BUTTON 1
#define A_BUTTON 2
#define DOWN 4
#define RIGHT 8
#define UP 16
#define LEFT 32
}
void loop() {
uint8t buttons = display.getInput();
if(buttons & LEFT) {
display.print("Pressing Left!");
}
}
I get an error:
testsketch:14: error: 'display' was not declared in this scope
'uint8t' was not declared in this scope.
For now, yes. They include the functions that allow you to draw and write to the screen. I covered them here: Reference Page for Development
You will need to get them from here, and then include them the same way the Breakout example game does, as well as call the initial screen setup function: https://github.com/Arduboy/ArduBreakout
This is a great start, we are going to build a full on tutorial how to get you started with the Arduboy. It will start assuming youāve never used programming languages before and finish you off that you can write text and draw images to the screen and move them around with the buttons.
Youāll be able to jump in at whatever level you are comfortable at. Examples like this will be perfect for the page so thanks so much for helping out while Iāve been away running the kickstarter campaign!
This is on the list of things Iāve added to the API. Iāll push a pull request in the next few days. I went with this:
if (arduboy.pressed(LEFT_BUTTON + RIGHT_BUTTON))
You pass in a bit mask of buttons and it returns true/false depending on whether all the buttons you requested are pressed at the current moment. You could also use | above but since the constants are bits it works just as easy to add them.
I hadnāt considered ānegativeā press queries⦠is that needed? IE, not_pressed?