Joypad-Game-Higher and Higher

From Microduino Wiki
Jump to: navigation, search


We adopt Microduino-Joypad-Game to play the game Higher and Higher, which can be controlled by gravity perception.

Bill of Material

  • Microduino Equipment
Module Number Function
Microduino-Core 1 Core board
Microduino-USBTTL 1 Program download
Microduino-Joypad 1
Microduino-10DOF/zh 1


TFT library: Joypad lib: 10DOF library: Code:


  • Step 4: Open the program example
    • Acquire gravity induction and by this time, we only use the data of the Y-axis.
 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
  //==========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;
    • Switch the code of the joystick and button control:
    int acc_readX() {
    val= constrain(Angel_accY, -64, 64); // use Y for orientation
    val= -1 * constrain(Joypad.readJoystickX()/8, -64, 64); // use Y for orientation
  // Serial.println(val);

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:
    if(score > highscore){
      if(score < 64000) {
        EEPROM.write(0, score);
        EEPROM.write(1, score>>8);
      else { // bad value, zero out
      //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;
  • Four ways of jumping:
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;
  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;
  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;
  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;
  • 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.