|
| 1 | + |
| 2 | +JoystickV2Unit |
| 3 | +============== |
| 4 | + |
| 5 | +.. include:: ../refs/unit.joystickv2unit.ref |
| 6 | + |
| 7 | +The joystick is an input unit for control, utilizing an I2C communication interface and supporting three-axis control signals (X/Y-axis analog input for displacement and Z-axis digital input for key presses). It is ideal for applications like gaming and robot control. |
| 8 | + |
| 9 | +Support the following products: |
| 10 | + |
| 11 | +|JoystickV2Unit| |
| 12 | + |
| 13 | +Micropython Example:: |
| 14 | + |
| 15 | + import os, sys, io |
| 16 | + import M5 |
| 17 | + from M5 import * |
| 18 | + from unit import JoystickV2Unit |
| 19 | + from hardware import * |
| 20 | + i2c = I2C(1, scl=22, sda=21) |
| 21 | + joystick = JoystickV2Unit(i2c) |
| 22 | + joystick.read_adc_value() |
| 23 | + joystick.read_button_status() |
| 24 | + joystick.set_rgb_led(255, 0, 0) |
| 25 | + joystick.get_rgb_led() |
| 26 | + joystick.set_deadzone_position(200, 200) |
| 27 | + while True: |
| 28 | + joystick.read_axis_position() |
| 29 | + |
| 30 | +UIFLOW2 Example: |
| 31 | + |
| 32 | + |example.svg| |
| 33 | + |
| 34 | +.. only:: builder_html |
| 35 | + |
| 36 | +class JoystickV2Unit |
| 37 | +-------------------- |
| 38 | + |
| 39 | +Constructors |
| 40 | +------------ |
| 41 | + |
| 42 | +.. class:: JoystickV2Unit(i2c, address) |
| 43 | + |
| 44 | + Initialize the JoystickV2 Unit. |
| 45 | + |
| 46 | + :param I2C i2c: I2C port to use. |
| 47 | + :param int address: I2C address of the JoystickV2 Unit. |
| 48 | + |
| 49 | + UIFLOW2: |
| 50 | + |
| 51 | + |init.svg| |
| 52 | + |
| 53 | + |
| 54 | +Methods |
| 55 | +------- |
| 56 | + |
| 57 | +.. method:: JoystickV2Unit.set_axis_x_invert(invert) |
| 58 | + |
| 59 | + Invert the X-axis of the joystick. |
| 60 | + |
| 61 | + :param bool invert: Whether to invert the X-axis. |
| 62 | + |
| 63 | + UIFLOW2: |
| 64 | + |
| 65 | + |set_axis_x_invert.svg| |
| 66 | + |
| 67 | +.. method:: JoystickV2Unit.set_axis_y_invert(invert) |
| 68 | + |
| 69 | + Invert the Y-axis of the joystick. |
| 70 | + |
| 71 | + :param bool invert: Whether to invert the Y-axis. |
| 72 | + |
| 73 | + UIFLOW2: |
| 74 | + |
| 75 | + |set_axis_y_invert.svg| |
| 76 | + |
| 77 | +.. method:: JoystickV2Unit.set_axis_swap(swap) |
| 78 | + |
| 79 | + Swap the X-axis and Y-axis of the joystick. |
| 80 | + |
| 81 | + :param bool swap: Whether to swap the X-axis and Y-axis. |
| 82 | + |
| 83 | + UIFLOW2: |
| 84 | + |
| 85 | + |set_axis_swap.svg| |
| 86 | + |
| 87 | +.. method:: JoystickV2Unit.read_adc_value() |
| 88 | + |
| 89 | + Read the ADC value of the joystick. |
| 90 | + |
| 91 | + |
| 92 | + UIFLOW2: |
| 93 | + |
| 94 | + |read_adc_value.svg| |
| 95 | + |
| 96 | +.. method:: JoystickV2Unit.read_button_status() |
| 97 | + |
| 98 | + Read the button status of the joystick. |
| 99 | + |
| 100 | + |
| 101 | + UIFLOW2: |
| 102 | + |
| 103 | + |read_button_status.svg| |
| 104 | + |
| 105 | +.. method:: JoystickV2Unit.set_rgb_led(r, g, b) |
| 106 | + |
| 107 | + Set the RGB LED color of the joystick. |
| 108 | + |
| 109 | + :param int r: The red value (0-255). |
| 110 | + :param int g: The green value (0-255). |
| 111 | + :param int b: The blue value (0-255). |
| 112 | + |
| 113 | + UIFLOW2: |
| 114 | + |
| 115 | + |set_rgb_led.svg| |
| 116 | + |
| 117 | +.. method:: JoystickV2Unit.get_rgb_led() |
| 118 | + |
| 119 | + Get the RGB LED color of the joystick. |
| 120 | + |
| 121 | + |
| 122 | + UIFLOW2: |
| 123 | + |
| 124 | + |get_rgb_led.svg| |
| 125 | + |
| 126 | +.. method:: JoystickV2Unit.set_axis_x_mapping(adc_neg_min, adc_neg_max, adc_pos_min, adc_pos_max) |
| 127 | + |
| 128 | + Set the mapping parameters of the X-axis. |
| 129 | + |
| 130 | +ADC Raw 0 65536 |
| 131 | + |------------------------------------------------------| |
| 132 | +Mapped -4096 0 0 4096 |
| 133 | + |---------------------|-dead zone-|--------------------| |
| 134 | + adc_neg_min adc_neg_max adc_pos_min adc_pos_max |
| 135 | + |
| 136 | + |
| 137 | + :param int adc_neg_min: The minimum ADC value of the negative range. |
| 138 | + :param int adc_neg_max: The maximum ADC value of the negative range. |
| 139 | + :param int adc_pos_min: The minimum ADC value of the positive range. |
| 140 | + :param int adc_pos_max: The maximum ADC value of the positive range. |
| 141 | + |
| 142 | + UIFLOW2: |
| 143 | + |
| 144 | + |set_axis_x_mapping.svg| |
| 145 | + |
| 146 | +.. method:: JoystickV2Unit.set_axis_y_mapping(adc_neg_min, adc_neg_max, adc_pos_min, adc_pos_max) |
| 147 | + |
| 148 | + Set the mapping parameters of the Y-axis. |
| 149 | + |
| 150 | +ADC Raw 0 65536 |
| 151 | + |------------------------------------------------------| |
| 152 | +Mapped -4096 0 0 4096 |
| 153 | + |---------------------|-dead zone-|--------------------| |
| 154 | + adc_neg_min adc_neg_max adc_pos_min adc_pos_max |
| 155 | + |
| 156 | + |
| 157 | + :param int adc_neg_min: The minimum ADC value of the negative range. |
| 158 | + :param int adc_neg_max: The maximum ADC value of the negative range. |
| 159 | + :param int adc_pos_min: The minimum ADC value of the positive range. |
| 160 | + :param int adc_pos_max: The maximum ADC value of the positive range. |
| 161 | + |
| 162 | + UIFLOW2: |
| 163 | + |
| 164 | + |set_axis_y_mapping.svg| |
| 165 | + |
| 166 | +.. method:: JoystickV2Unit.set_deadzone_adc(x_adc_raw, y_adc_raw) |
| 167 | + |
| 168 | + Set the dead zone of the joystick. |
| 169 | + |
| 170 | + :param int x_adc_raw: The dead zone of the X-axis. Range is 0 to 32768. |
| 171 | + :param int y_adc_raw: The dead zone of the Y-axis. Range is 0 to 32768. |
| 172 | + |
| 173 | + UIFLOW2: |
| 174 | + |
| 175 | + |set_deadzone_adc.svg| |
| 176 | + |
| 177 | +.. method:: JoystickV2Unit.set_deadzone_position(x_pos, y_pos) |
| 178 | + |
| 179 | + Set the dead zone of the joystick. |
| 180 | + |
| 181 | + :param int x_pos: The dead zone of the X-axis. Range is 0 to 4096. |
| 182 | + :param int y_pos: The dead zone of the Y-axis. Range is 0 to 4096. |
| 183 | + |
| 184 | + UIFLOW2: |
| 185 | + |
| 186 | + |set_deadzone_position.svg| |
| 187 | + |
| 188 | +.. method:: JoystickV2Unit.read_axis_position() |
| 189 | + |
| 190 | + Read the position of the joystick. |
| 191 | + |
| 192 | + |
| 193 | + UIFLOW2: |
| 194 | + |
| 195 | + |read_axis_position.svg| |
| 196 | + |
| 197 | +.. method:: JoystickV2Unit.set_address(address) |
| 198 | + |
| 199 | + Set the I2C address of the JoystickV2 Unit. |
| 200 | + |
| 201 | + :param int address: The I2C address to set. |
| 202 | + |
| 203 | + UIFLOW2: |
| 204 | + |
| 205 | + |set_address.svg| |
| 206 | + |
| 207 | +.. method:: JoystickV2Unit.read_fw_version() |
| 208 | + |
| 209 | + Read the firmware version of the JoystickV2 Unit. |
| 210 | + |
| 211 | + |
| 212 | + UIFLOW2: |
| 213 | + |
| 214 | + |read_fw_version.svg| |
| 215 | + |
| 216 | + |
| 217 | + |
0 commit comments