BrainGamer Intro

BrainGamer Intro

The provided driver allows users to control the BrainGamer controller without needing to understand 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.

Python

#############################
###   BrainGamer Driver   ###
#############################
from DUELink.DUELinkController import DUELinkController
class BrainGamer:
    def __init__(self, brainpad:DUELinkController):
        self.BrainPad = brainpad
    def RocketX(self)-> int:
        x = self.BrainPad.Analog.Read(4)
        return x    
    def RockerY(self)-> int: 
        y = self.BrainPad.Analog.Read(3)
        return y
    ### Vibrator ###
    def Vibrator(self, enable: bool):
        self.BrainPad.Digital.Write(8, not enable)
        return
    ### Read Buttons ###
    def ButtonUp(self):
        u =  not self.BrainPad.Digital.Read(14,1)
        return u
    def ButtonDown(self):
        d =  not self.BrainPad.Digital.Read(15,1)
        return d
    def ButtonLeft(self):
        l = not self.BrainPad.Digital.Read(13,1)
        return l
    def ButtonRight(self):
        r = not self.BrainPad.Digital.Read(16,1)
        return r

C#

///////////////////////////
///  BrainGamer Driver  ///
///////////////////////////
class BrainGamer
{
    DUELinkController BrainPad;
    public BrainGamer(DUELinkController brainpad){
        BrainPad = brainpad;
    }
    public int RockerX(){
        var x = BrainPad.Analog.Read(4);
        return (x);
    }
    public int RockerY(){
        var y = BrainPad.Analog.Read(3);
        return (y);
    }
    public void Vibrator(bool enable){
        BrainPad.Digital.Write(8, !enable);
    }
    public bool ButtonUp(){
        return !BrainPad.Digital.Read(14, BrainPad.Pin.PullUp);
    }
    public bool ButtonDown(){
        return !BrainPad.Digital.Read(15, BrainPad.Pin.PullUp);
    }
    public bool ButtonLeft(){
        return !BrainPad.Digital.Read(13, BrainPad.Pin.PullUp);
    }
    public bool ButtonRight(){
        return !BrainPad.Digital.Read(16, BrainPad.Pin.PullUp);
    }
}

JavaScript

///////////////////////////
///  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 easily.

Python

Gamer = BrainGamer(BrainPad)
x = Gamer.RockerX()
y = Gamer.RockerY()

C#

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

JavaScript

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!