|
|
|
@ -1,12 +1,14 @@
|
|
|
|
|
// ESPNOWSkate Reciever by Lukas Bachschwell this device SLAVE =D
|
|
|
|
|
// ESPNOWSkate Receiver by Lukas Bachschwell this device SLAVE =D
|
|
|
|
|
#include <Servo.h>
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
|
#include "SSD1306.h"
|
|
|
|
|
#include <esp_now.h>
|
|
|
|
|
#include <WiFi.h>
|
|
|
|
|
|
|
|
|
|
static const int esc1pin = 15;
|
|
|
|
|
static const int esc2pin = 13;
|
|
|
|
|
#define esc1pin 15
|
|
|
|
|
#define esc2pin 13
|
|
|
|
|
#define fallbackpin 36
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Servo esc1;
|
|
|
|
|
Servo esc2;
|
|
|
|
@ -14,15 +16,13 @@ SSD1306 display(0x3c, 5, 4);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//#define pairingMode
|
|
|
|
|
#define FAILSAFE 90
|
|
|
|
|
#define CONNECTION_TIMEOUT 200
|
|
|
|
|
#define CONNECTION_TIMEOUT 300
|
|
|
|
|
#define CHANNEL 1
|
|
|
|
|
long lastPacket = 0;
|
|
|
|
|
|
|
|
|
|
bool isConnected = false;
|
|
|
|
|
|
|
|
|
|
// ESPNOW Functions ############################
|
|
|
|
|
//
|
|
|
|
|
// config AP
|
|
|
|
|
void configDeviceAP(bool hidden) {
|
|
|
|
|
bool result = WiFi.softAP("ESK8", "ESK8_Password+vD8z2YAvoDBW?Zx", CHANNEL, hidden);
|
|
|
|
@ -34,7 +34,6 @@ void configDeviceAP(bool hidden) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void writeServos(uint8_t firstServo, uint8_t secondServo) {
|
|
|
|
|
isConnected = true;
|
|
|
|
|
esc1.write(firstServo);
|
|
|
|
|
esc2.write(secondServo);
|
|
|
|
|
}
|
|
|
|
@ -65,14 +64,16 @@ void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
Serial.begin(115200);
|
|
|
|
|
Serial.println("ESPNowSkate Reciever");
|
|
|
|
|
Serial.println("ESPNowSkate Receiver");
|
|
|
|
|
|
|
|
|
|
display.init();
|
|
|
|
|
display.flipScreenVertically();
|
|
|
|
|
display.setFont(ArialMT_Plain_16);
|
|
|
|
|
|
|
|
|
|
esc1.attach(esc1pin);
|
|
|
|
|
esc2.attach(esc2pin);
|
|
|
|
|
// Init escs, min and max value similar as Traxxas TQI 1100, 1900
|
|
|
|
|
// chanel, minAngel, maxAngel, minPulseWidth, maxPulseWidth
|
|
|
|
|
esc1.attach(esc1pin, 0, 0, 180, 1100, 1900);
|
|
|
|
|
esc2.attach(esc2pin, 1, 0, 180, 1100, 1900);
|
|
|
|
|
|
|
|
|
|
//Set device in AP mode to begin with
|
|
|
|
|
WiFi.mode(WIFI_AP);
|
|
|
|
@ -100,10 +101,14 @@ void setup() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
if(isConnected) {
|
|
|
|
|
if(millis() - lastPacket > CONNECTION_TIMEOUT ) {
|
|
|
|
|
isConnected = false;
|
|
|
|
|
writeServos(FAILSAFE, FAILSAFE);
|
|
|
|
|
}
|
|
|
|
|
if(millis() - lastPacket > CONNECTION_TIMEOUT ) {
|
|
|
|
|
isConnected = false;
|
|
|
|
|
int failsafeValue = map(analogRead(fallbackpin), 0, 4095, 0, 180);
|
|
|
|
|
writeServos(failsafeValue, failsafeValue);
|
|
|
|
|
display.clear();
|
|
|
|
|
char buf[25];
|
|
|
|
|
sprintf(buf, "FAIL: %i", failsafeValue);
|
|
|
|
|
display.drawString(2, 0, buf);
|
|
|
|
|
display.display();
|
|
|
|
|
}
|
|
|
|
|
}
|