-
Notifications
You must be signed in to change notification settings - Fork 0
/
eServoGiro.ino
65 lines (60 loc) · 1.41 KB
/
eServoGiro.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <ArduinoJson.h>
#include <I2Cdev.h>
#include <MPU6050_6Axis_MotionApps20.h>
#include <MPU6050_6Axis_MotionApps20.h>
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include <Wire.h>
#endif
#define OUTPUT_READABLE_YAWPITCHROLL
#define INTERRUPT_PIN 19
#include "credentials.h"
#include "ap-utils.hpp"
#include "server/server-utils.hpp"
#include "mpu-utils.hpp"
#include "servo-utils.hpp"
byte SERVO[3] = {13, 14, 27};
float ANGLE[3] = {0, 0, 0};
SERVER srv;
accessPoint ap;
gyroscope gyro;
servomotor servo;
void setup()
{
Serial.begin(115200);
servo.begin(SERVO);
Serial.println("Iniciando...");
Serial.println("Cargando datos...");
const size_t CAPACITY = JSON_ARRAY_SIZE(16);
for (int i = 0; i < 3; i++)
{
iot.id[i] = String(i) + "-axis";
iot.value[i] = 0.0F;
iot.angle[i] = map(iot.value[i], -180, 180, 0, 90);
}
iot.Json = data.load(iot.value, iot.angle);
Serial.println("Conectando a la red...");
ap.load();
ap.print();
Serial.println("Iniciando servidor...");
srv.load();
srv.run();
Serial.println("Cargando MPU6050...");
gyro.begin();
Serial.println("Servidor iniciado");
}
void loop()
{
if (iot.lock)
gyro.updates(ANGLE);
for (byte i = 0; i < 3; i++)
{
float cache = ANGLE[i] * 180 / M_PI;
iot.value[i] = float(cache);
cache = (180 + cache) / 2;
iot.angle[i] = byte(cache);
servo.write(&i, &iot.angle[i]);
}
}