Microduino-Joypad-Standard Angry Birds
OutlineHere we adopt Microduino-Joypad-Game to play Angry Birds on the computer. PrincipleWe 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
Download
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
Microduino-Joypad_Getting_start
Video |