Help me how to control joystick

Hello Everybody,
I need you help,
I want to use joystick in my project.
But I dont know how to add virtual pin which can be used on joystick on MERGE mode.
Code for joystick on merge mode I found in the internet but configure joystick was made in old BLYNK app.

BLYNK_WRITE(V3) {
 int x = param[0].asInt();
 int y = param[1].asInt();
 // x =  -10..-2 -1 0 1 2 ..10
 // Y =  -10..-2 -1 0 1 2 ..10
 if ((x == 0) && (y == 0)) // stop
 {
   motorSpeed(0, LOW, LOW, 0, LOW, LOW);
 }

please help how to add virtual button for joystick on merge mode

Create a datastream and set the data type to string.

1 Like

Now it is found but I can not send signal to

 int x = param[0].asInt();
 int y = param[1].asInt();
 // x =  -10..-2 -1 0 1 2 ..10
 // Y =  -10..-2 -1 0 1 2 ..10

Try this:

BLYNK_WRITE(V3)
{   
  int value = param.asInt(); // Get value as integer

  // The param can contain multiple values, in such case:
  int x = param[0].asInt();
  int y = param[1].asInt();
}

Have you tried adding serial prints after these lines of code, to see what values (if any) you are getting for x and y ?

Pete?

1 Like

Nice idea.

@PeteKnight I assigned the joystick widget and a labeled value widget to the same vpin and I got this

Very good Idea.

  int x = param[0].asInt();
   Serial.print(x);
   int y = param[1].asInt();
   Serial.print(" - ");
   Serial.println(y);
  // x =  -10..-2 -1 0 1 2 ..10
  // Y =  -10..-2 -1 0 1 2 ..10
  if ((x == 0) && (y == 0)) // stop
  {
    motorSpeed(0, LOW, LOW, 0, LOW, LOW);
  }

I think range is
for x= 0-255
for y=0-255
middle is 128 for both

   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.0.1 on ESP32

[240] --------------------------
[243] Product:  machine2
[246] Hardware: 1.0.0
[248] Firmware: 0.1.0 (build Oct 30 2021 16:55:34)
[252] Token:    ...KsaZ
[254] Device:   ESP32 @ 240MHz
[257] MAC:      7C:9E:BD:61:40:CC
[260] Flash:    4096K
[262] ESP sdk:  v3.3.5-1-g85c43024c
[265] Chip rev: 1
[267] Free mem: 277136
[269] --------------------------
[272] INIT => CONNECTING_NET
[275] Connecting to WiFi: UGE_MAX
[2568] Using Dynamic IP: 192.168.41.66
[2568] CONNECTING_NET => CONNECTING_CLOUD
[2578] Connecting to blynk.cloud:443
[4819] Certificate OK
[5133] Ready (ping: 312ms).
[5269] CONNECTING_CLOUD => RUNNING
DEVICE OFF
128 - 128
128 - 101
128 - 232
128 - 255
129 - 255
130 - 255
131 - 255
132 - 255
128 - 128
141 - 88
253 - 122
255 - 125
255 - 126
255 - 125
255 - 124
128 - 128
87 - 82
3 - 100
1 - 109
1 - 116
0 - 117
0 - 118
0 - 119
0 - 120
0 - 122
0 - 124
1 - 111
16 - 66
27 - 49
35 - 39
36 - 39
35 - 40
36 - 39
40 - 34
46 - 30
51 - 25
57 - 21
64 - 17
84 - 8
98 - 4
103 - 2
115 - 1
121 - 0
129 - 0
130 - 0
131 - 0
132 - 0
133 - 0
134 - 0
135 - 0
136 - 0
137 - 0
138 - 0
139 - 1
128 - 128

How can I make range for x and y like this
x = from -10 to 10
y = from -10 to 10

Use the map command.

Pete.

1 Like

thank you guys you helped me to solve my problem

1 Like

You’re welcome.