#include #ifdef WITH_DEBUGGING_ON #include // debugging support via GDBStub over UART #endif #include "PCA9685.h" extern "C" { #include "user_interface.h" } // OTA & WEB #include "wifi_credentials.h" #include "ota.h" #include "httpserver.h" // BOARD #define ESP12_LED 2 #define NODEMCU_LED 16 // PWM #include "treppe.h" os_timer_t timer1; uint8_t timer_flag = 0; Treppe stairs(16); // WIFI const char* ssid = STASSID; const char* password = STAPSK; void timerCallback(void *pArg) { *((int *) pArg) += 1; stairs.task(); } // port 80, root directory of server '/' HTTPServer httpServer(80, "/"); uint32_t _t=0; #define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("us") #define TIMEIF_US(_f, _l, _str) _t=micros(); _f; _t=micros()-_t; if(_t > _l) { SP_US(_str, _t); } // =============================================== void setup() { #ifdef WITH_DEBUGGING_ON Serial.begin(460800); gdbstub_init(); #else Serial.begin(115200); #endif Serial.println(F("Booting ....")); pinMode(NODEMCU_LED, OUTPUT); pinMode(ESP12_LED, OUTPUT); Wire.begin(); // Wire must be started first Wire.setClock(1000000); // Supported baud rates are 100kHz, 400kHz, and 1000kHz WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.waitForConnectResult() != WL_CONNECTED) { Serial.println("Connection Failed! Rebooting..."); delay(5000); ESP.restart(); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); ota_setup(); httpServer.start(); Serial.println("HTTP server started !"); stairs.setup(); Serial.println("PCA9685 connected !"); os_timer_setfn(&timer1, timerCallback, &timer_flag); os_timer_arm(&timer1, 20, true); } #include void loop() { // if(stairs.getState() == 0) { // delay(1000); // // uint32_t t = rand() % stairs.getTicks(); // // uint32_t d = rand() % 2; // // stairs.setTick(t); // // stairs.setDirection(d); // stairs.setDirection(!stairs.getDirection()); // stairs.setState(1); // } TIMEIF_US(ArduinoOTA.handle(), 10000, "OTA"); TIMEIF_US(httpServer.handleClient(), 10000, "HTTP"); }