Remote control from smartphone
In two previous articles, I talked about using a smartphone to control a toy car, either directly by voice or using another smartphone via Bluetooth. But management was primitive - the team was given, the car carried out the command, stopped and waited for the next command. This was due to the high speed of the car for room conditions (approximately 1.2 m / s), as well as the long time the command was given and the inability to quickly intervene in the movement using the menu. Even the regular remote control did not give control. In the new version of the remote control with a graphical interface, I decided to use PWM to adjust the speed and simulate steering.

The picture shows the machine, which controls the smartphone, and below the smartphone with a running remote control program for bluetooth.
At the top of the screen is a slider (green circle) moved by a finger.

When you remove your finger from the screen, the relative distance from the slider to the left edge of the screen is transferred to the control smartphone, where the latitudinal modulation of the pulse signal is formed.
The smallest signal ratio of 20%, the largest 80%. The theoretical possible frequency is 10 Hz. In fact, probably around 4 - 5 Hz, since the signals for modulation go in the general flow of commands, and some of them also have a time delay. Therefore, at a low duty cycle, vibration is clearly visible.
Two green buttons - upper forward movement, lower back. Right red button - to stand still. Two white buttons - stop programs on the remote control and on a typewriter. At the bottom of the screen are three purple buttons for choosing the direction of movement to the left, right and right. With
on, the corresponding mode, in the center of the button appears a circle of smaller diameter and the same, but darker color. To control the direction of motion in addition to the buttons, I also used the accelerometer. When the smartphone is horizontal, the projection of the gravitational acceleration vector on the axis 0Y equals 0, which corresponds to the movement straight (see figure above).

If you lift the left side of the smartphone, the projection will be with a + sign, which will correspond to the movement to the right.

If you raise the right side with the sign - that will correspond to the movement to the left.
The program reads the accelerometer readings and sends the corresponding commands to the smartphone controlling the car, displaying the mode on the buttons.
This is how the remote control works. The work of the car control program has also undergone changes, but not very significant. In the future, I want to supplement the program with the functions of memorizing commands and executing them in automatic mode.

The picture shows the machine, which controls the smartphone, and below the smartphone with a running remote control program for bluetooth.
At the top of the screen is a slider (green circle) moved by a finger.

When you remove your finger from the screen, the relative distance from the slider to the left edge of the screen is transferred to the control smartphone, where the latitudinal modulation of the pulse signal is formed.
GR.GET.POSITION c1, xx, yy
r6=(xx-xc)*(xx-xc)+(yy-yc)*(yy-yc)
IF r6<rkn THEN
GR.TOUCH touched, x, y
IF y < 120THENDO
GR.TOUCH touched, x, y
GR.GET.POSITION c1, x1,z1
GR.MOVE c1 ,x-x1, y1
GR.RENDER
UNTIL !touched
ENDIF
GR.GET.POSITION c1, x1,z1
POPUP STR$(x1/w)
BT.WRITE "#"+STR$(x1/w)
ENDIF
The smallest signal ratio of 20%, the largest 80%. The theoretical possible frequency is 10 Hz. In fact, probably around 4 - 5 Hz, since the signals for modulation go in the general flow of commands, and some of them also have a time delay. Therefore, at a low duty cycle, vibration is clearly visible.
Two green buttons - upper forward movement, lower back. Right red button - to stand still. Two white buttons - stop programs on the remote control and on a typewriter. At the bottom of the screen are three purple buttons for choosing the direction of movement to the left, right and right. With
on, the corresponding mode, in the center of the button appears a circle of smaller diameter and the same, but darker color. To control the direction of motion in addition to the buttons, I also used the accelerometer. When the smartphone is horizontal, the projection of the gravitational acceleration vector on the axis 0Y equals 0, which corresponds to the movement straight (see figure above).

If you lift the left side of the smartphone, the projection will be with a + sign, which will correspond to the movement to the right.

If you raise the right side with the sign - that will correspond to the movement to the left.
The program reads the accelerometer readings and sends the corresponding commands to the smartphone controlling the car, displaying the mode on the buttons.
SENSORS.READ1, sx, sy, sz
IF (sy<=1)&(sy>-1)&(lrsh) THEN
rsh=1
lsh=1
lrsh=0
GR.HIDE cc13
GR.HIDE cc15
GR.SHOW cc17
GR.RENDER
BT.write "f"
pause 100
ENDIF
IF (sy>2)&(rsh) THEN
rsh=0
lsh=1
lrsh=1
GR.HIDE cc13
GR.HIDE cc17
GR.SHOW cc15
GR.RENDER
BT.write "r"
pause 100
ENDIF
IF (sy<-2)&(lsh) THEN
lsh=0
rsh=1
lrsh=1
GR.HIDE cc17
GR.HIDE cc15
GR.SHOW cc13
GR.RENDER
BT.write "l"
pause 100
ENDIF
This is how the remote control works. The work of the car control program has also undergone changes, but not very significant. In the future, I want to supplement the program with the functions of memorizing commands and executing them in automatic mode.