Joypad-Standard-上一百层
概述我们采用Microduino-Joypad-Game来实现上一百层,并且可以通过重力感来实现控制。 材料清单
下载TFT库:https://github.com/wasdpkj/libraries/tree/master/_01_Microduino_TFT Joypad库:https://github.com/wasdpkj/libraries/tree/master/_08_Microduino_Shield_Joypad 10DOF库:https://github.com/wasdpkj/libraries/tree/master/_05_Microduino_10DOF 代码: 调试
void mpu6050()
{
accelgyro.getMotion6(&ax,&ay,&az,&gx,&gy,&gz);//获取三个轴的加速度和角速度
//======一下三行是对加速度进行量化,得出单位为g的加速度值
Ax=ax/16384.00;
Ay=ay/16384.00;
Az=az/16384.00;
//==========以下三行是用加速度计算三个轴和水平面坐标系之间的夹角
// Angel_accX=atan(Ax/sqrt(Az*Az+Ay*Ay))*180/3.14;
Angel_accY=atan(Ay/sqrt(Ax*Ax+Az*Az))*180/3.14;
//Angel_accZ=atan(Az/sqrt(Ax*Ax+Ay*Ay))*180/3.14;
}
int acc_readX() {
if(Joypad.readButton(CH_SWITCH_L)&&Joypad.readButton(CH_SWITCH_R))
{
mpu6050();
val= constrain(Angel_accY, -64, 64); // use Y for orientation
}
else
val= -1 * constrain(Joypad.readJoystickX()/8, -64, 64); // use Y for orientation
return(val);
// Serial.println(val);
}
默认是左右边两边的拨动开关拨到上面是重力感应控制,否则摇杆控制,玩家可以更改切换选择方式。
if(score > highscore){
if(score < 64000) {
EEPROM.write(0, score);
EEPROM.write(1, score>>8);
}
else { // bad value, zero out
EEPROM.write(0,0);
EEPROM.write(1,0);
}
//drawString(1, s_height+3, "HIGHSCORE!", p_color_default, 1);
// tft.drawString(1, s_height+3, "HIGHSCORE!", p_color_default, 1);
drawInt(score, 120, s_height+3, p_color_default, background);
highscore = score;
}
switch (b_onUseID){
case 0:
drawString(1, s_height+3, "Jet pack", b_colors[b_onUseID], 1);
// tft.drawString(1, s_height+3, "Jet pack", b_colors[b_onUseID], 1);
b_max = 100;
b_remaining = b_max;
break;
case 1:
drawString(1, s_height+3, "Frog legs", b_colors[b_onUseID], 1);
// tft.drawString(1, s_height+3, "Frog legs", b_colors[b_onUseID], 1);
b_max = 100;
b_remaining = b_max;
break;
case 2:
drawString(1, s_height+3, "Testosterone", b_colors[b_onUseID], 1);
// tft.drawString(1, s_height+3, "Testosterone", b_colors[b_onUseID], 1);
b_max = 1;
b_remaining = b_max;
break;
case 3:
drawString(1, s_height+3, "Low gravity", b_colors[b_onUseID], 1);
// tft.drawString(1, s_height+3, "Low gravity", b_colors[b_onUseID], 1);
b_max = 255;
b_remaining = b_max;
break;
}
步骤五:编译代码,成功后选择对应的板卡和COM端口下载。下载完毕后就可以进行体验了。
|