Tinkercad Coding – Piper

LET'S CODE WHAT YOUR BUTTONS AND JOYSTICK DO

Now that you've seen how the inputs, or buttons on your buttonpad and your joystick, are wired up to the Arduino Micro, let's figure out how to code your specific inputs to have desired outputs. For example, if we want to make the bottom button in the buttonpad be used to jump in Minecraft we can program that button (input) to replicate the "space bar" on a keyboard. To do this, we're going to use BlocklyDuino.

We want to use our joystick and our buttons to interact with Minecraft.

So what exactly do we need for Minecraft and how do we want to map it to our joystick and buttonpad?

Basic Minecraft keyboard functions are shown in this diagram.


How can we map each of the Command Center Buttons to Keyboard Inputs?

Below are each of the independent pieces you are coding. The first row is the name of the function, the second row is the pin on the Arduino Micro that the function will map to and the third row is the keyboard command we want the input to replicate.

VERTICAL Joystick Motion

HORIZONTAL Joystick Motion

Joystick PUSH Tactile Button

LEFT Button

DOWN Button

RIGHT Button

UP Button

A0 Pin

A1 Pin

D13 Pin

D10 Pin

D9 Pin

D8 Pin

D7 Pin

"E"

Not Mapped

Left Shift

"A"

"S"

"D"

"W"


What Does Arduino Code Look Like?

Below is a working code editor called BlocklyDuino that is embedded into this web page. This allows you to program the Command Center using block coding, view the code as an Arduino Sketch (coded in C), and download it to your Command Center.

Note: You can use BlocklyDuino to upload your code to Arduinos, but we will use code in Arduino IDE Create in the next page which can reference keyboard and mouse libraries

Above are the connections as wired for the Command Center.

Using BlocklyDuino, you can drag and drop blocks to map your Arduino pins to different button variables.

Tinkercad Coding

Try it out on the left! Toggle between the blocks view and the Arduino view to see how the logic you've constructed carries over to coding language.

Feel good about how it all works? Go ahead and hit NEXT