Странности с GY-85(акселерогирокомпас) и ESP-01
- Войдите на сайт для отправки комментариев
Сб, 25/03/2017 - 22:52
Сразу к делу:
Есть код
#include <ESP8266WiFi.h> #include <DNSServer.h> #include <ESP8266WebServer.h> #include <Adafruit_NeoPixel.h> #include "GY_85.h" #define PIN 2 #define NUMPIXELS 14 #define BRIGHTNESS 50 Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); int r, g, b, j = 0; #include <Wire.h> int headingCZDegrees; int cx; GY_85 GY85; //create the object const byte DNS_PORT = 53; IPAddress apIP(192, 168, 1, 1); DNSServer dnsServer; ESP8266WebServer webServer(80); String responseHTML = "" "<!DOCTYPE html><html><head><title>CaptivePortal</title></head><body>" + String(cx) + "<h1>Hello World!</h1><p>This is a captive portal example. All requests will " "be redirected here.</p></body></html>"; void setup() { WiFi.mode(WIFI_AP); WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); WiFi.softAP("DNSServer CaptivePortal example"); // if DNSServer is started with "*" for domain name, it will reply with // provided IP to all DNS request dnsServer.start(DNS_PORT, "*", apIP); // replay to all requests with same HTML webServer.onNotFound([]() { webServer.send(200, "text/html", "<!DOCTYPE html><html><head><title>CaptivePortal</title></head><body>" + String(headingCZDegrees) + " - " + String(cx) + "</body></html>"); }); webServer.begin(); Wire.pins(3, 0); Wire.begin(3, 0); strip.begin(); GY85.init(); //delay(500); for (int i = 0; i < NUMPIXELS; i++) { strip.setPixelColor(i, strip.Color(15, 15, 15)); strip.show(); delay(50); } delay(500); } void loop() { dnsServer.processNextRequest(); webServer.handleClient(); for (byte i = 0; i < NUMPIXELS; i++) { strip.setPixelColor(i, strip.Color(0, 0, 0)); } float headingCZ = atan2(GY85.compass_y( GY85.readFromCompass() ), GY85.compass_x( GY85.readFromCompass() )); if (headingCZ < 0) headingCZ += 2 * PI; if (headingCZ > 2 * PI) headingCZ -= 2 * PI; headingCZDegrees = headingCZ * 180 / M_PI; cx = map(headingCZDegrees, 0, 360, 0, NUMPIXELS); for (int i = 0; i <= cx; i++) { strip.setPixelColor(i, strip.Color(0, 0, 100)); } strip.show(); }
Собственно проблема в том, что на Arduino Mega этот код (с изменениями, касающимися отображения переменных) работает как надо, а на ESP переменная headingCZDegrees не принимает значения большие прямого угла. В чём причина и как это можно лечить?