a game controller

I eventually forgot the name of a game we’ve played. This is a Ziv’s favorite game, so I did not want to insist on playing Super Mario.

We’ve figured out all the buttons, but I have not figured out the game rules  🙂

IMG_0494 copy

int lastButtonState = LOW;        // state of the button last time you checked

boolean mouseIsActive = true;    // whether or not the Arduino is controlling the mouse

void setup() {

// initialize mouse control:

Mouse.begin();

// initialize serial communication:

Serial.begin(9600);

// make pin 2 through 5 inputs:

pinMode(2, INPUT);

pinMode(2, INPUT);

pinMode(3, INPUT);

pinMode(4, INPUT);

pinMode(5, INPUT);

pinMode(6, INPUT);

}

void loop() {

if(mouseIsActive) {

// read the other buttons:

int button2State = digitalRead(3);

int button3State = digitalRead(4);

int button4State = digitalRead(5);

int button5State = digitalRead(6);

int button6State = digitalRead(2);

if (button2State == HIGH) {

Serial.println(“R”);

Mouse.move(1, 0, 0);      // move right

}

if (button3State == HIGH) {

Serial.println(“L”);

Mouse.move(-1, 0, 0);     // move left

}

if (button4State == HIGH) {

Serial.println(“D”);

Mouse.move(0, 1, 0);      // move down

}

if (button5State == HIGH) {

Serial.println(“U”);

Mouse.move(0, -1, 0);      // move up

}

if (button6State == HIGH) {

Mouse.click(MOUSE_LEFT);  // move CLICK

}

}

}

Advertisements

Comments are closed.