Microduino-Joypad-Standard愤怒的小鸟
概述我们采用Microduino-Joypad-Game在电脑上玩愤怒的小鸟。 原理采用[Microduino-CoreUSB/zh]]模拟一个键盘,游戏控制需要用到【鼠标】、【鼠标左键】,【鼠标右键】键,通过Microduino-Joypad-Game的键模拟出这些就可以进行游戏了。 材料清单
下载
代码: #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);
}
}
调试
步骤五:编译代码,成功后选择对应的板卡(Microduino-CoreUSB)和COM端口下载。下载完毕后就可以进行体验了。•
视频 |