Dear Blynk,
I came across this platform yesterday, and I’ve been testing and trying some stuff with it. I would like to integrate it with something bigger, and that’s what I’ve been trying.
I’m using the Arduino Uno, wired to my PC via USB. I’m running a local server on that PC and my phone is connected via the same network over wifi.
That’s all working, it’s connecting etc. But the thing is, the response time of the app is very slow. Some buttons don’t even seem to work, even though they’re (I think) programmed correctly and on a very rare occasion they do work.
Here a screenshot of the app and all the code for the program (there’s a lot of math but I don’t think that’s the problem. Let me know if you need some more explanation or something else.
Thanks for helping me out!
PICTURE:
CODE:
#include <SoftwareSerial.h>
#include <BlynkSimpleStream.h>
#define BLYNK_PRINT DebugSerial
SoftwareSerial DebugSerial(2, 3);
WidgetLED led1(V25);
char auth[] = "___";
#include <Servo.h>
#include <math.h>
Servo camerarotatemotor;
Servo drivemotor;
double pi = M_PI;
double rg = (180/pi);
double camerarotate;
double motordolly = 0;
double gradenperstap = 1;
double gradenperstapcam = 1;
int isTracking = 0;
int getFocus = 0;
double distance = 3;
double radius = 8.11;
double ypoint_focus;
double xpoint_focus;
double ypointCamera;
double xpointCamera;
double angleposition;
int driveposition = 0;
BLYNK_WRITE(V5)
{
distance = param.asInt();
}
BLYNK_WRITE(V6)
{
isTracking = param.asInt();
if(isTracking == 1)
{
led1.setValue(255);
}
else
{
led1.setValue(0);
}
}
BLYNK_WRITE(V7)
{
getPointFocusCoordinates(driveposition, angleposition);
}
BLYNK_WRITE(V8)
{
if(isTracking != 1)
{
driveposition = param.asInt();
}
}
BLYNK_WRITE(V9)
{
if(isTracking != 1)
{
angleposition = param.asInt();
}
}
void setup()
{
DebugSerial.begin(9600);
Serial.begin(9600);
Blynk.begin(auth, Serial);
camerarotatemotor.attach(8);
camerarotatemotor.write(0);
drivemotor.attach(9);
drivemotor.write(30);
}
void loop()
{
Blynk.run();
Blynk.virtualWrite(V1, angleposition);
Blynk.virtualWrite(V2, driveposition);
if(isTracking == 1)
{
for(int i = -30; i<=30; i++)
{
angleposition = giveposition(i);
Blynk.virtualWrite(V1, angleposition);
Blynk.virtualWrite(V2, driveposition);
driveposition = i;
if(isTracking != 1)
{
break;
}
delay(2000);
}
}
delay(10);
}
double giveposition(double dollyang)
{
xpointCamera = -radius * sin(dollyang / rg);
ypointCamera = radius * cos(dollyang / rg) ;
double dTempX = xpoint_focus - xpointCamera;
double dTempY = ypoint_focus - ypointCamera;
double dTempA = sqrt(dTempX * dTempX + dTempY * dTempY);
double slopeangle = (asin(-dTempX / dTempA) * rg);
if(dTempY < 0)
{
slopeangle = 180 - slopeangle;
}
return angleposition = slopeangle - dollyang;
}
void getPointFocusCoordinates(double dollyangstart, double camerarotstart)
{
xpointCamera = -radius * sin(dollyangstart / rg);
ypointCamera = radius * cos(dollyangstart / rg);
xpoint_focus = -(distance * sin((camerarotstart + dollyangstart) / rg)) + xpointCamera;
ypoint_focus = (distance * cos((camerarotstart + dollyangstart) / rg)) + ypointCamera;
Blynk.virtualWrite(V20, xpoint_focus);
Blynk.virtualWrite(V21, ypoint_focus);
}