micro:bit Project Joystick with LED Position Feedback Tutorial
This is a very easy project.
Hello Microbit Friends
Welcome to another microbit tutorial, today we are connecting a 2 axis joystick to our microbit.
makecode download here: makecode.microbit.org/88588-6...
We’re going to show you how to wire it up and the code needed to move a dot on the led display in response to joystick movement.
Lets get started.
The joystick we’re using is from an electronics kit, it’s the same style as used in games controllers such as xbox.
To make connection easy we’re using an expansion board with our microbit which brings us to our first discussion point on connections.
We want to use the led display to feedback joystick position so we cannot use any pins that are needed to drive the led display. When we press the joystick down activating the button we want the buzzer to sound so that rules out P0 as well.
The joystick has 5 connections, 0v, 5v, VRx, VRy, and SW. Working through these, connect 0v, then 5v. VRx and VRy are the potentiometer outputs, we cannot use P0 as we’ll be using that for the Buzzer, so we will connect VRx to P1 and VRy to P2. Our final connection is for the switch, the next single use pin is P8 so that is where we will connect SW.
Lets move onto the code needed.
First we’ll deal with the switch connected to P8.
We need a pull up on this input pin so we will add that in the startup code. If you don’t have this activated then you’ll not read the input correctly.
We want to continuously read the switch state on P8 if the button is pressed we’ll play a sound so this code will go in the forever loop.
Now to deal with the analogue inputs from the joystick. We want to move a dot across the display to match the joystick movement.
We will use a plot x y block for this. The analogue input values will range from 0 to 1023 and we want to map this to the display coordinates, 0 to 4.
We’ll download the code and test it out.
We hope you enjoyed this tutorial video, please subscribe and tick the notification bell so you’ll not miss our next upload.
Comment down below what microbit project you would like to see us make next.
This video shows you how to connect a joystick to your micro:bit and is presented as an easy project tutorial idea.
6 авг 2024