Read analog value from VEX gamepad accelerometer
Simulink Coder Support Package for ARM Cortex-based VEX Microcontroller / Gamepad
The Gamepad Accelerometer block is used to read an analog value from the VEX® gamepad accelerometer based on the axis of rotation (x or y) of the gamepad.
The output for this block ranges from –128 to 127. There are two accelerometers on the VEX gamepad, and their axes are aligned perpendicular to each other. Rotation of the VEX gamepad along either the horizontal axis (1) or the vertical axis (2) results in an output value in the range –128 to 127. You can use this analog value to control peripherals, such as a DC motor, that are connected to the VEX microcontroller.
Port_1— Analog signal used during simulation
Connect a source block such as the Gamepad Simulator block from the Utilities library in Simulink® Support Package for ARM® Cortex®-based VEX Microcontroller.
This port appears only when you select the Add input port for simulation parameter.
Port_1— Analog value from accelerometer
The block output ranges from –128 to 127 based on the axis selected and the orientation of the gamepad.
During simulations, without the hardware, this block emits zeroes if there is no Source block connected the simulation input port (see Block Produces Zeros or Does Nothing in Simulation (Simulink)).
Joystick— Joystick number
This parameter is read only. You can have a pair of VEX gamepads to control the peripherals connected to the VEX microcontroller. However, in the VEX Robotics and BEST Robotics competitions, teams are allowed only one gamepad. Therefore, Joystick is set to 1 by default, and it cannot be changed.
Axis of Rotation (X-axis = 1, Y-axis = 2)— Select axis of rotation of gamepad
The axis of rotation determines which accelerometer is used to generate the output value. Select 1 for the horizontal x-axis and 2 for the vertical y-axis.
Add input port for simulation— Add input port to simulate input acceleration
Select this check box to add an input port to specify an analog value for acceleration.
Sample time— Sample time for obtaining analog value of acceleration
0.02(default) | positive real number
How often the Gamepad Accelerometer block should read the values from the gamepad, specified in seconds. The default value is 0.02 seconds.
If you select the Add input port for simulation check box, the Sample time parameter is hidden and its value is inherited.
During code generation, any simulation block that is connected to the input port of Gamepad Accelerometer block is ignored and has no effect on the generated code.