empowering creative people

Videos / Circuit Playground Express Workshop - Chapter 5 - Keyboard, Mouse and Gamepad

The Circuit Playground Express can be recognized as an HID device by a computer, and we can use MakeCode to program it! Under the Advanced menu, there is an option for “Extensions” there we can add the ability to use the Circuit Playground as a Mouse, Keyboard, or even a gamepad! New blocks will appear to be able to perform these functions once they are selected under extensions.

Search Videos

Related Content

Transcript

+

Hi, welcome back to the Circuit Playground Express online workshop, in this section we're going to learn how to turn your Circuit Playground Express into a human interface device. So that's a keyboard, a mouse or a gamepad and when we create this code and MakeCode, it makes your computer automatically recognize the Circuit Playground, as a mouse, a keyboard or gamepad, so your commands are accepted automatically.

So, let's take a look I’ve got a simple sketch on the Circuit Playground that moves the mouse with a button A and B press and we can see on the screen that my mouse is moving left and right and then I created a keyboard command, that when I press pin A1 it types out some words for me. So, you can do just about anything with the Circuit Playground Express as a keyboard or Mouse that a normal keyboard or mouse can do. you're just limited to how many inputs that you have on the Circuit Playground. So, let's look at how to do it so to make our Circuit Playground into a keyboard or mouse we need to use extensions, so we go into the advanced option and down at the bottom we have extensions and here we have gamepad, keyboard and mouse. So, to add them we just click on the button, so now we have a menu for keyboard, and we have a menu for mouse, so we'll just I'll jump over to the sketch that I made earlier and we see here the sketch that I showed has an if statement for the pennies pressed. We have a keyboard type command and then you enter in the string of words or single letter that you want to type whenever that command is met and then a pause afterwards because if you've got a long string and you press the button multiple times it will overlap them and jumble up your letters so it's good to have a pause so they don't overlap and then I have some while loops for when button A is pressed the mouse will move to pixels in a positive direction on the x-axis and when B is pressed it'll move in the negative direction on the x-axis.

We can also use the keyboard to emulate media buttons like play, pause, mute we can do function keys, so like f1 through f12 or just create text rings with commands from the Circuit Playground and under the mouse option we can do mouse clicks, so it's important to note that if you do mouse button up that's unclicked and mouse button down is clicked and it's good to use a while loop for mouse commands for the clicks. So if you hold the button then it holds the mouse click down, so you can say drag something across the screen and the mouse move gives you an option in number of pixels to move the mouse so if you want to jump a fixed distance like 200 pixels to the right, then you'd set that in there if you want to hold the button down and move to have it move around like a more normal Mouse you'd want it to move one pixel at a time. So it can move slow enough to react too and we can also turn the wheel so it's good to make mouse programs where you press an input and then something moves rather than something in a loop that moves the mouse around because there's a chance that you could lose control of your computer a little bit where the mouse will just start clicking everywhere and you'll be unable to control it until you unplug the Circuit Playground or maybe that's something you want to do but you could theoretically schedule some clicks and movements to say have your Circuit Playground Express play Farmville for you all the time, so you never need to grind away at it. So, let's look one more time at what we've made I've got the move left and right with the button presses and then typing a string by pressing a one.

So that wraps up this section on how to create a keyboard or mouse using certain your Circuit Playground Express. Stick around in the next section we're going to learn about different ways to program other than MakeCode on your Circuit Playground.

comments