Introduction
The dual-axis joystick module has two independent potentiometers, one per axis, and can be easily connected to the breadboard!Â
In this guide, we will create a fast reaction-time game with the micro:bit, and use the joystick module as a controller.Â
After completing this guide, you will have learned how to program a basic game as well as its controls.
-
-
-
-
-
-
-
-
let yVal = 0 let xVal = 0 basic.forever(function () { xVal = pins.analogReadPin(AnalogPin.P0) yVal = pins.analogReadPin(AnalogPin.P1) if (xVal > 600) { basic.showLeds(` . . # . . . # . . . # # # # # . # . . . . . # . . `) } else if (xVal < 400) { basic.showLeds(` . . # . . . . . # . # # # # # . . . # . . . # . . `) } else if (yVal < 400) { basic.showLeds(` . . # . . . . # . . # . # . # . # # # . . . # . . `) } else if (yVal > 600) { basic.showLeds(` . . # . . . # # # . # . # . # . . # . . . . # . . `) } })
-
let globalScore = 0 globalScore = 0 basic.showString("'Start!'")
-
let state = 0 let globalScore = 0 globalScore = 0 basic.showString("'Start!'") basic.forever(function () { for (let round = 0; round <= 4; round++) { basic.clearScreen() basic.pause(1000) state = Math.randomRange(0, 3) if (state == 0) { basic.showLeds(` . . # . . . # . . . # # # # # . # . . . . . # . . `) basic.pause(500) } else if (state == 1) { basic.showLeds(` . . # . . . . . # . # # # # # . . . # . . . # . . `) basic.pause(500) } else if (state == 2) { basic.showLeds(` . . # . . . . # . . # . # . # . # # # . . . # . . `) basic.pause(500) } else if (state == 3) { basic.showLeds(` . . # . . . # # # . # . # . # . . # . . . . # . . `) basic.pause(500) } } basic.showNumber(globalScore) })
-
-