forked from madhephaestus/ESP32ServoServer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLunaMotherboardFirmware.ino
75 lines (60 loc) · 1.54 KB
/
LunaMotherboardFirmware.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
66
67
68
69
70
71
72
73
74
75
#include "Arduino.h"
#include <SimplePacketComs.h>
#include <WiFi.h>
#include <PacketEvent.h>
#include <Esp32SimplePacketComs.h>
#include <server/UDPSimplePacket.h>
#include <Preferences.h>
#include <Esp32WifiManager.h>
#include <wifi/WifiManager.h>
#include <server/NameCheckerServer.h>
#include "src/ServoServer.h"
#include "src/GetIMU.h"
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <Wire.h>
// SImple packet coms implementation useing WiFi
UDPSimplePacket coms;
// WIfi stack managment state machine
WifiManager manager;
//The setup function is called once at startup of the sketch
String * name = new String("midnight");
Adafruit_BNO055 bno;
GetIMU * sensor;
ServoServer * servos;
int toggled = 0;
void setup()
{
pinMode(HEARTBEAT_LED, OUTPUT);
manager.setup();
sensor = new GetIMU();
Wire.begin(IMU_SCL,IMU_SDA);
Serial.println("Loading with name: "+name[0]);
servos=new ServoServer();
//Initialise the sensor
bno = Adafruit_BNO055(55, 0x28);
if (bno.begin()) {
delay(1000);
bno.setExtCrystalUse(true);
sensor->startSensor(&bno);
}else{
Serial.print(
"Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
}
coms.attach(new NameCheckerServer(name));
coms.attach((PacketEvent * )sensor);
coms.attach((PacketEvent * )servos);
toggled = millis();
}
// The loop function is called in an endless loop
void loop()
{
manager.loop();
coms.server();
servos->loopServos();
if(millis()-toggled >500)
{
digitalWrite(HEARTBEAT_LED, !digitalRead(HEARTBEAT_LED));
toggled = millis();
}
}