Michael Brucato
Published

PokeBall Game Controller

Everyone that Plays Pokemon games Always wants to hold a pokeball in their hands. Now you can feel like you have a Pokemon in your hands

IntermediateFull instructions provided12 hours52
PokeBall Game Controller

Things used in this project

Hardware components

Circuit Playground Express
Adafruit Circuit Playground Express
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×2
Alligator Clips
Alligator Clips
×6

Software apps and online services

MakeCode
Microsoft MakeCode

Story

Read more

Schematics

Pokeball Schematics

Code

PokeBall Controller

Arduino
You Turn the right knob left to right in order to go left and right.
You Turn the left knob left to right in order to go up and down.
Shake the Pokeball to interact.
Press Button A to Access Key Items
Press Button B to Access the Menu
let x = 0
let Set = 0
let MoveHorizontal = 0
let MoveVertical = 0
let MoveHorMap = 0
let MoveVertMap = 0
let ball = false
input.buttonA.onEvent(ButtonEvent.Click, function () {
    keyboard.key("A", KeyboardKeyEvent.Press)
})
input.buttonB.onEvent(ButtonEvent.Click, function () {
    keyboard.key("S", KeyboardKeyEvent.Press)
})
forever(function () {
    let pressed = false
    x = input.acceleration(Dimension.X)
    Set = Math.map(x, -10, 10, 0, 255)
    MoveHorizontal = pins.A2.analogRead()
    MoveVertical = pins.A5.analogRead()
    MoveHorMap = Math.map(MoveHorizontal, 0, 1023, 0, 10)
    MoveVertMap = Math.map(MoveVertical, 0, 1023, 0, 10)
    if (MoveHorMap == 10) {
        keyboard.functionKey(KeyboardFunctionKey.LeftArrow, KeyboardKeyEvent.Down)
        pause(200)
    } else if (MoveHorMap != 0 && MoveHorMap != 10) {
        keyboard.functionKey(KeyboardFunctionKey.LeftArrow, KeyboardKeyEvent.Up)
        keyboard.functionKey(KeyboardFunctionKey.RightArrow, KeyboardKeyEvent.Up)
        pause(200)
    } else if (pressed == false && MoveHorMap == 0) {
        keyboard.functionKey(KeyboardFunctionKey.RightArrow, KeyboardKeyEvent.Down)
    }
    if (MoveVertMap == 10) {
        keyboard.functionKey(KeyboardFunctionKey.UpArrow, KeyboardKeyEvent.Down)
        pause(200)
    } else if (MoveVertMap != 0 && MoveVertMap != 10) {
        keyboard.functionKey(KeyboardFunctionKey.UpArrow, KeyboardKeyEvent.Up)
        keyboard.functionKey(KeyboardFunctionKey.DownArrow, KeyboardKeyEvent.Up)
        pause(200)
    } else if (pressed == false && MoveVertMap == 0) {
        keyboard.functionKey(KeyboardFunctionKey.DownArrow, KeyboardKeyEvent.Down)
        pause(200)
    }
    if (ball == false && Set >= 35) {
        ball = true
        keyboard.key("x", KeyboardKeyEvent.Press)
        pause(1000)
    } else if (ball == true && Set <= 35) {
        ball = false
        keyboard.key("x", KeyboardKeyEvent.Up)
        pause(1000)
    }
})

Credits

Michael Brucato

Michael Brucato

4 projects • 0 followers

Comments