查看“Joypad-Game-Higher and Higher”的源代码
←
Joypad-Game-Higher and Higher
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{| style="width: 800px;" |- | ==Outline== We adopt Microduino-Joypad-Game to play the game Higher and Higher, which can be controlled by gravity perception. ==Bill of Material== *Microduino Equipment {|class="wikitable" |- |Module||Number||Function |- |[[Microduino-Core]]||1||Core board |- |[[Microduino-USBTTL]] ||1|| Program download |- |[[Microduino-Joypad]] ||1|| |- |[[Microduino-10DOF/zh]] ||1|| |} [[File: Microduino-Joypad-snake.jpg|600px|center|thumb]] ==Download== TFT library:https://github.com/wasdpkj/libraries/tree/master/_01_Microduino_TFT Joypad lib.:https://github.com/wasdpkj/libraries/tree/master/_08_Microduino_Shield_Joypad 10DOF library:https://github.com/wasdpkj/libraries/tree/master/_05_Microduino_10DOF Code: ==Debugging== *Step 1: Prepare Microduino-Joypad-Game and you can refer: [[Microduino-Joypad_Getting_start]] *Step 2: Stack [[Microduino-Core]], [[Microduino-10DOF]] and [[Microduino-USBTTL]] on the panel of Microduino-Joypad-Game; *Step 3: Download libraries and codes needed and update the library to compiler 【[[Install Arduino IDE Microduino Program Library Support Package]]】 *Step 4: Open the program example **Acquire gravity induction and by this time, we only use the data of the Y-axis. <source lang="cpp"> void mpu6050() { accelgyro.getMotion6(&ax,&ay,&az,&gx,&gy,&gz);//Acquire the acceleration and the angular velocity of the x,y,z axis. //======Below are the quantized values of the acceleration Ax=ax/16384.00; Ay=ay/16384.00; Az=az/16384.00; //==========Below are the angles between the three axes and the horizontal coordinate system. // 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; } </source> **Switch the code of the joystick and button control: <source lang="cpp"> 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); } </source> Gravity induction control is the default setting by turning the left and the right switches to the top. So, the opposite operation is joystick control. Users can change the setting according to personal needs. *The highest score is saved in EEPROM: <source lang="cpp"> 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; } </source> *Four ways of jumping: <source lang="cpp"> 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; } </source> *Step 5: Compile the code and select the right board and COM port for download. After that, you can have fun with Microduino. *Experience: **Make sure the status of the two switches. If they’re all toggled upside, you should adopt gravity induction to control. Otherwise, you should use the left joystick to control. **You can change different way of jumping while the ball falls on different level. **That the ball falls on the ground means GAME OVER. If the score is higher than before, it will then be written in EEPROM. |}
返回至
Joypad-Game-Higher and Higher
。
导航菜单
个人工具
创建账户
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
Welcome
首页
创客大赛
大赛详情
3D打印
安装月球车
图形化编程
操控月球车
升级月球车
编程工具下载
软件下载
Arduino
Processing
Mixly
Scratch
模块套件
Microduino 102
mCookie 102
mCookie 202
mCookie 302
IBC
其他
应用套件
四轴飞行器
平衡车
小车CUBE
音乐播放器
刷卡音乐播放器
wifi气象站
彩虹音乐触摸灯
分贝检测仪
迎门汇报
LED点阵时钟
LED点阵屏幕
硬件
mCookie
Sensor
Microduino
MicroWrt
MicroNux
MicroRobot-Core
MicroRobot-CoreESP
ideaBoard
ideaBox
MicroMV
MicroAI
帮助
常见问题
帮助
工具
链入页面
相关更改
特殊页面
页面信息