Microduino-Joypad-Standard Angry Birds

来自Microduino Wikipedia
跳转至: 导航搜索

Outline

Here we adopt Microduino-Joypad-Game to play Angry Birds on the computer.

Principle

We adopt [Microduino-CoreUSB]] to simulate a keyboard. By Microduino-Joypad-Game, we can simulate keys of a computer mouse and play the game.

Bill of Material

  • Microduino Equipment
Module Number Function
Microduino-CoreUSB 1 Core board
Microduino-Joypad-Standard 1 Remote control

Download

  • Library file download:https://github.com/wasdpkj/libraries;
    • You will need:_01_Microduino_TFT and _08_Microduino_Shield_Joypad. Decompress the downloaded library file to libraries of Arduino IDE and then restart IDE compiler.

Code:

#include <Joypad.h>

int mouseX,mouseY,xValue,yValue;

boolean Joy_sw,Joy1_sw;

boolean sw_l,sw_r;

void setup()
{
  Serial.begin(9600);       // initialize serial communication with your computer
  Mouse.begin();            // take control of the mouse
  Keyboard.begin();
  delay(2000);
} 

void loop()
{
  xValue = Joypad.readJoystick1X();        // read the joystick's X position
  yValue = Joypad.readJoystick1Y();        // read the joystick's Y position

  sw_l=Joypad.readButton(CH_SWITCH_L);
  sw_r=Joypad.readButton(CH_SWITCH_R);

  Joy_sw=Joypad.readButton(CH_JOYSTICK_SW);
  Joy1_sw=Joypad.readButton(CH_JOYSTICK1_SW);

  if(sw_r==true)
  {
    mouseX = map( xValue,-512, 512, 15, -15);  // map the X value to a range of movement for the mouse X
    mouseY = map( yValue,-512, 512, -15, 15);  // map the Y value to a range of movement for the mouse Y
    Mouse.move(mouseX, mouseY, 0);                 // move the mouse

    if(Joy_sw==true) 
      Mouse.release(MOUSE_LEFT); 
    else
      Mouse.press(MOUSE_LEFT);

    if(Joy1_sw==true) 
      Mouse.release(MOUSE_RIGHT); 
    else
      Mouse.press(MOUSE_RIGHT);

    delay(30);
  }
}

Debugging

  • Step 1: Prepare Microduino-Joypad-Game and you can refer to:

Microduino-Joypad_Getting_start

  • Step 4: Compile the code and choose the right board (Microduino-CoreUSB) and COM port for download.
  • Experience:
    • Open the game
    • Start the switch on the right top and control.
    • Simulate the right joystick as the mouse.
    • The left joystick as the left button of the mouse and the right joystick as the right button.
  • Control the left joystick to catch the bird and the right joystick to move around and shoot.

Video

http://v.youku.com/v_show/id_XNzM3NTA1NzQw.html