Gamepad Module

Game Pad
Description

This module provides the gamepad controller layout in three different modes:

  1. Digital Mode: This mode is the standard mode with 10 buttons namely
    Up, Down, Right, Left, Triangle, Circle, Cross, Square, Select, and Start.
  2. Joystick Mode: In this mode, the Up, Down, Right, and Left buttons are replaced by the Joystick which sends data in polar coordinates. The radius varies from 0-7 and the angle varies from 0°- 360° in steps of 15°.
  3. Accelerometer Mode: This mode is similar to the joystick mode. Instead of sliding the button on the screen, you must tilt your Smartphone to make it move.
Available in

Introduction

The Gamepad Controller Module is one of the input modules, using which user can give commands to the board using buttons and analog joystick present in different layouts:

  1. Digital Mode
  2. Joystick Mode
  3. Accelerometer Mode

You can toggle between the different modes using setting option present on the top right corner of the module.

Dabble Game Pad Switch Mode

Digital Mode

Dabble Gamepad Controller

The digital mode is the default mode when the module opens. It has 10 digital buttons whose data is sent to the device when they are pressed or released.

  1. Up
  2. Down
  3. Left
  4. Right
  5. Triangle
  6. Cross
  7. Square
  8. Circle
  9. Select
  10. Start

Only the digital state of each button is sent to the device, whether it is pressed or not.

Joystick Mode

The joystick mode has both button and joystick in the layout.

Dabble Game Pad Joystick

The joystick is present on the left side of the layout. It sends 4 data to the device:

  1. X value: The value of the x position (on the horizontal axis) of the white dot in the joystick. It is an integer value and varies from -7 to 7. At the center, the value is 0.
  2. Y value: The value of the y position (on the verticle axis) of the white dot in the joystick. It is an integer value and varies from -7 to 7. At the center, the value is 0.
  3. Radial value: The distance from the center of the joystick. This value varies from 0 to 7. At the center, the value is 0 and on the perimeter of the joystick, the value is 7.
  4. Angle: The angle is the angle between the positive x-axis and the line joining the center and the current position of the dot. It varies from 0 to 360 at a step of 15 degrees.

The buttons work the same as the digital mode. Only 6 digital buttons are present in the joystick Mode:

  1. Triangle
  2. Cross
  3. Square
  4. Circle
  5. Select
  6. Start

Accelerometer Mode

The accelerometer mode is pretty the same as the analog mode, the only difference is that the joystick present in this mode is controlled with the accelerometer sensor present in the phone.

The values given to the hardware device is the same as the joystick: 4 analog values and 6 digital values.

Arduino IDE Functions

Header

To include the GamePad module in the Arduino program, you have to include the following header:

#define CUSTOM_SETTINGS

#define INCLUDE_GAMEPAD_MODULE

After defining the above mention headers, you have to include the dabble library:

#include <Dabble.h>

You can download the zip of Arduino Library for

  1. evive, Uno, Mega, and Nano – Dabble-Arduino 
  2. ESP32 – Dabble-ESP32

depending on the board you are using.

Enabling Bluetooth Communication

To enable Bluetooth communication, you have to initialize serial communication using the following code:

  1. For evive and Arduino Mega, Uno and Nano
    Dabble.begin(Baud_Rate);

    Here Baud_Rate is the baud rate set for the Bluetooth module. With evive, you normally get 115200 baud rate modules.

  2. For ESP32
    Dabble.begin("Bluetooth_Name");

    In place of Bluetooth_Name  enter name that you want to keep for Bluetooth of ESP32. Default name given in the library is “MyEsp32”. 

Refreshing the data

To refresh the data that the device has got from the mobile app, you have to use the following line of code:

Dabble.processInput();

Gamepad Functions

Following are the function available for the GamePad module:

FunctionReturn TypeFunction Brief DecriptionReturning Value
isUpPressed()BooleanThe function tells whether the Up button is pressed or not.1 when Up button is pressed; 0 when Up button is not pressed.
isDownPressed()BooleanThe function tells whether the Down button is pressed or not.1 when Down button is pressed; 0 when Down button is not pressed.
isLeftPressed()BooleanThe function tells whether the Left button is pressed or not.1 when Left button is pressed; 0 when Left button is not pressed.
isRightPressed()BooleanThe function tells whether the Right button is pressed or not.1 when Right button is pressed; 0 when Right button is not pressed.
isTrianglePressed()BooleanThe function tells whether the Triangle button is pressed or not.1 when Triangle button is pressed; 0 when Triangle button is not pressed.
isCirclePressed()BooleanThe function tells whether the Circle button is pressed or not.1 when Circle button is pressed; 0 when Circle button is not pressed.
isCrossPressed()BooleanThe function tells whether the Cross button is pressed or not.1 when Cross button is pressed; 0 when Cross button is not pressed.
isSquarePressed()BooleanThe function tells whether the Square button is pressed or not.1 when Square button is pressed; 0 when Square button is not pressed.
isStartPressed()BooleanThe function tells whether the Start button is pressed or not.1 when Start button is pressed; 0 when Start button is not pressed.
isSelectPressed()BooleanThe function tells whether the Select button is pressed or not.1 when Select button is pressed; 0 when Select button is not pressed.
getAngle()IntegerThis function returns the angle value between the x-axis and the line joining the dot and the center of the joystick.The value varies form 0 to 360 degrees with a step of 15 degrees.
getRadius()IntegerThe function returns the distance between the center of the joystick and the dot.The value varies from 0 to 7.
getXaxisData()floatThe fuction returns the x postion of the dot on the joystick.The value varies from -7 to 7.
getYaxisData()floatThe fuction returns the y postion of the dot on the joystick.The value varies from -7 to 7.

PictoBlox (Scratch) Blocks

Digital Mode

To use GamePad in digital mode, you will need a boolean block is () pressed on gamepad? block.

is pressed on gamepad 2

You just have to choose a button from the dropdown i.e Up, Down, Left, Right, Triangle, Circle, Cross, Square, Start or Select. 

evive Notes Icon
Note: When you are using this module with Arduino Uno, Mega, and Nano,  you have to set the Bluetooth baud rate to the baud rate of the Bluetooth module to have proper communication between the board and the module. To set the baud rate you have to use set bluetooth baud rate to () block.

set bluetooth baud rate to

Joystick & Accelerometer Mode

To use GamePad as a regular Joystick, you have to use a reporter blockget () from Gamepad”.

get from gamepad 2

In its drop-down, you will find 4 things i.e. X Value, Y Value, Angle and Radial Distance. Using these 4 values, you can develop a logic to control the left side of Gamepad and rest 6 digital controls will work similarly to digital mode.

evive Alert
Alert: There are some bugs in the joystick interface of the Gamepad module for iOS devices. Hence you will face problems in getting joystick values properly. The bug will be removed soon from the iOS app, however, the android app is working fine if possible then you can use the Gamepad module on any android device.

Examples

Click here to view Arduino IDE Example for Gamepad Module

In order to explain how to use the functions available for this module the data returned from this function is printed on Serial Monitor. Follow the steps given below:

  • Copy code from below as per your board in Arduino IDE. 
  • Upload code
  • Connect with Dabble via Bluetooth and open Gamepad

evive

Mega, Uno, and Nano

ESP32

Click here to view PictoBlox (Scratch) Example for Gamepad Module

Digital Mode

In this example, we are controlling a robot using the digital mode. The robot is the same as we build the one in this project: https://thestempedia.com/project/smartphone-controlled-mobile-robot.

Given below is the full script of the same:

dabble gamepad mobile robot example

You can download the PictoBlox program from here:

  1. evive: Smartphone Controlled Robot with Dabble
  2. Arduino Uno: Smartphone Controlled Robot with Dabble for Arduino Uno

In this example, we are displaying all the parameters on the evive Display

get from gamepad example

You can download the Scratch Program from here: Gamepad Module Analog value Display evive

Projects

Humanoid-Bipedal-Robot
DIY Humanoid Bipedal Robot

This project will show you how to make an expressive and energetic humanoid bipedal robot.

Stair-Climbing-Robot
DIY Stair Climbing Robot

This project will show you how to make a Smartphone-controlled stair-climbing robot.

Leave a Reply

Close Menu
×

Cart