JS BrainGamer Intro

BrainGamer Intro

The provided driver allows users to control the BrainGamer controller without understanding advanced details.

Software driver (library) is provided to start using BrainGamer with minimal needed knowledge. Future gaming lessons cover details on using the driver.

The driver provided below needs to be copied to your BrainGamer projects.

///////////////////////////
///  BrainGamer Driver  ///
///////////////////////////

/// Put it before the main code

class BrainGamer {
    constructor(brainpad) {
        this.BrainPad = brainpad;
    }

    RockerX() {
        var x = this.BrainPad.Analog.Read(4);
        return x;
    }

    RockerY() {
        var y = this.BrainPad.Analog.Read(3);
        return y;
    }

    async Vibrator(enable) {
        await this.BrainPad.Digital.Write(8, !enable);
    }

    async ButtonUp() {
        return !await this.BrainPad.Digital.Read(14, this.BrainPad.Pin.PullUp);
    }

    async ButtonDown() {
        return !await this.BrainPad.Digital.Read(15, this.BrainPad.Pin.PullUp);
    }

    async ButtonLeft() {
        return !await this.BrainPad.Digital.Read(13, this.BrainPad.Pin.PullUp);
    }

    async ButtonRight() {
        return !await this.BrainPad.Digital.Read(16, this.BrainPad.Pin.PullUp);
    }
}

Using the BrainGamer is now done quickly.

var Gamer = new BrainGamer(BrainPad);
var x = await Gamer.RockerX();
var y = await Gamer.RockerY();

What’s Next?

You are now ready to start making games with the BrainGamer. Start with making BrainGamer Pong game.

Content Licensing
Newsletter

Twitter Feed
Hot off the press!