commit a5211a1d493fc79cc09627a4edc9a781dcb07ea0 Author: VogelT Date: Thu Jan 18 11:48:35 2024 +0100 LED Controler diff --git a/ledcontroler/.cproject b/ledcontroler/.cproject new file mode 100644 index 0000000..acd801b --- /dev/null +++ b/ledcontroler/.cproject @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ledcontroler/.gitignore b/ledcontroler/.gitignore new file mode 100644 index 0000000..dcd90ee --- /dev/null +++ b/ledcontroler/.gitignore @@ -0,0 +1,2 @@ +/Release/ +/sloeber.ino.cpp diff --git a/ledcontroler/.project b/ledcontroler/.project new file mode 100644 index 0000000..37df492 --- /dev/null +++ b/ledcontroler/.project @@ -0,0 +1,85 @@ + + + ledcontroler + + + + + + io.sloeber.core.inoToCpp + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.core.ccnature + io.sloeber.arduinonature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + ArduinoAsync-master + 2 + WORKSPACE_LOC/ArduinoAsync-master + + + core/core + 2 + ECLIPSE_HOME/arduinoPlugin/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266 + + + core/variant + 2 + ECLIPSE_HOME/arduinoPlugin/packages/esp8266/hardware/esp8266/3.0.2/variants/d1_mini + + + libraries/ESP8266WiFi + 2 + ECLIPSE_HOME/arduinoPlugin/packages/esp8266/hardware/esp8266/3.0.2/libraries/ESP8266WiFi + + + libraries/ESPAsyncTCP-master + 2 + C:/Users/vogelt/Documents/Arduino/libraries/ESPAsyncTCP-master + + + libraries/ESPAsyncWebServer-master + 2 + C:/Users/vogelt/Documents/Arduino/libraries/ESPAsyncWebServer-master + + + libraries/FastLED-master + 2 + C:/Users/vogelt/Documents/Arduino/libraries/FastLED-master + + + libraries/Hash + 2 + ECLIPSE_HOME/arduinoPlugin/packages/esp8266/hardware/esp8266/3.0.2/libraries/Hash + + + libraries/SPI + 2 + ECLIPSE_HOME/arduinoPlugin/packages/esp8266/hardware/esp8266/3.0.2/libraries/SPI + + + libraries/Wire + 2 + ECLIPSE_HOME/arduinoPlugin/packages/esp8266/hardware/esp8266/3.0.2/libraries/Wire + + + diff --git a/ledcontroler/.settings/language.settings.xml b/ledcontroler/.settings/language.settings.xml new file mode 100644 index 0000000..1fd3f28 --- /dev/null +++ b/ledcontroler/.settings/language.settings.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ledcontroler/.settings/org.eclipse.core.resources.prefs b/ledcontroler/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..68a0304 --- /dev/null +++ b/ledcontroler/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=windows-1252 diff --git a/ledcontroler/.sproject b/ledcontroler/.sproject new file mode 100644 index 0000000..2e8d892 --- /dev/null +++ b/ledcontroler/.sproject @@ -0,0 +1,29 @@ +Config.Release.board.BOARD.ID=d1_mini +Config.Release.board.BOARD.MENU.baud=115200 +Config.Release.board.BOARD.MENU.dbg=Disabled +Config.Release.board.BOARD.MENU.eesz=4M2M +Config.Release.board.BOARD.MENU.exception=disabled +Config.Release.board.BOARD.MENU.ip=lm2f +Config.Release.board.BOARD.MENU.lvl=None____ +Config.Release.board.BOARD.MENU.mmu=3232 +Config.Release.board.BOARD.MENU.non32xfer=fast +Config.Release.board.BOARD.MENU.ssl=all +Config.Release.board.BOARD.MENU.stacksmash=disabled +Config.Release.board.BOARD.MENU.vt=flash +Config.Release.board.BOARD.MENU.wipe=none +Config.Release.board.BOARD.MENU.xtal=160 +Config.Release.board.BOARD.TXT=${SLOEBER_HOME}/arduinoPlugin/packages/esp8266/hardware/esp8266/3.0.2/boards.txt +Config.Release.board.PROGRAMMER.NAME= +Config.Release.board.UPLOAD.PORT=COM11 +Config.Release.compile.sloeber.extra.all= +Config.Release.compile.sloeber.extra.archive= +Config.Release.compile.sloeber.extra.assembly= +Config.Release.compile.sloeber.extra.c.compile= +Config.Release.compile.sloeber.extra.compile= +Config.Release.compile.sloeber.extra.cpp.compile= +Config.Release.compile.sloeber.extra.link= +Config.Release.compile.sloeber.size.custom= +Config.Release.compile.sloeber.size.type=RAW_RESULT +Config.Release.compile.sloeber.warning_level=NONE +Config.Release.compile.sloeber.warning_level.custom= +Config.Release.other.IS_VERSION_CONTROLLED=false diff --git a/ledcontroler/ledcontroler.ino b/ledcontroler/ledcontroler.ino new file mode 100644 index 0000000..be958f6 --- /dev/null +++ b/ledcontroler/ledcontroler.ino @@ -0,0 +1,323 @@ +#include +#include "Arduino.h" +#include +#include +#include +#include +#include + +const boolean DEBUG = true; +const boolean LED_RUN = true; + +boolean BUTTONSERVER_ACTIV = false; +boolean UPDATE_LEDS = false; + + +// Replace with your network credentials +const char *ssid = "FRITZ!BoxWZ"; +const char *password = "40360548708873074408"; +IPAddress ip(192, 168, 178, 12); +IPAddress subnet(255, 255, 255, 0); +IPAddress gateway(192, 168, 178, 1); + +const char *PARAM_INPUT_1 = "speed"; +const char *PARAM_INPUT_2 = "modus"; +// Create AsyncWebServer object on port 88 +AsyncWebServer server(88); +Async asyncEngine = Async(); +Async asyncEngineReset = Async(); + +/* + * define your ws2812fx presets + */ +#define LED_PIN_1 D7 +#define LED_PIN_2 D8 + +// Fastled: +#define NUM_LEDS_1 38 +#define NUM_LEDS_2 144 // Total of 216 LED's 24 x 9 Panels | 24, 48, 72, 96, 120, 144, 168, 192, 216 +#define MILLI_AMPS 2400 +#define LED_TYPE WS2812B +#define COLOR_ORDER_1 GRB +#define COLOR_ORDER_2 GRB +#define UPDATES_PER_SECOND 100 +#define BRIGHTNESS 64 +CRGB LEDsStatus[NUM_LEDS_1]; +//CRGB LEDsPanel[NUM_LEDS_2]; + +#define COOLING 55 +#define FRAMES_PER_SECOND 200 +bool gReverseDirection = false; +bool variDemo = false; +int ledOn = 0; + +void ledDemoApp(boolean start) { + variDemo = true; +} + + +void initWebService() { + + // Send a GET request to /update?output=&state= + server.on("/update", HTTP_GET, [](AsyncWebServerRequest *request) { + String inputMessage1; + String inputMessage2; + // GET input1 value on /update?output=&state= + if (request->hasParam(PARAM_INPUT_1) && request->hasParam(PARAM_INPUT_2)) { + inputMessage1 = request->getParam(PARAM_INPUT_1)->value(); + inputMessage2 = request->getParam(PARAM_INPUT_2)->value(); + //digitalWrite(inputMessage1.toInt(), inputMessage2.toInt()); + } + else { + inputMessage1 = "No message sent"; + inputMessage2 = "No message sent"; + } + /* + Serial.print("GPIO: "); + Serial.print(inputMessage1); + Serial.print(" - Set to: "); + Serial.println(inputMessage2); + */ + request->send(200, "text/plain", "OK"); + }); + + // ledfxon + server.on("/ledfxon", HTTP_GET, [] (AsyncWebServerRequest *request) { + + String inputMessage1; + String inputMessage2; + // GET input1 value on /ledfxon?speed=&modus= + if (request->hasParam(PARAM_INPUT_1) && request->hasParam(PARAM_INPUT_2)) { + inputMessage1 = request->getParam(PARAM_INPUT_1)->value(); + inputMessage2 = request->getParam(PARAM_INPUT_2)->value(); + } + else { + inputMessage1 = 100; + inputMessage2 = "SCAN"; + } + + int speedled = 100; + String modus = "FX_MODE_SCAN"; + + speedled = inputMessage1.toInt(); + inputMessage2.toUpperCase(); + modus = inputMessage2; + + //startFastLed(speedled, modus); + + request->send(200, "text/plain", "OK"); + }); + + server.on("/ledtest", HTTP_GET, [] (AsyncWebServerRequest *request) { + + request->send(200, "text/plain", "OK"); + }); + + server.on("/ledDemoOn", HTTP_GET, [] (AsyncWebServerRequest *request) { + ledDemoApp(true); + ledOn = 1; + request->send(200, "text/plain", "LED on"); + }); + + server.on("/ledDemoOff", HTTP_GET, [] (AsyncWebServerRequest *request) { + ledDemoApp(false); + ledOn = 0; + stopLed(); + request->send(200, "text/plain", "LED off"); + }); + + server.on("/ledmodus", HTTP_GET, [] (AsyncWebServerRequest *request) { + + String inputMessage1; + // GET input1 value on /ledfxon?speed=&modus= + if (request->hasParam(PARAM_INPUT_2)) { + inputMessage1 = request->getParam(PARAM_INPUT_2)->value(); + } + else { + inputMessage1 = "0"; + + } + + int modus = 0; + + modus = inputMessage1.toInt(); + + //changeModus(modus); + + String text = "Start Modus " + inputMessage1 + " OK"; + + request->send(200, "text/plain", text); + }); + + server.on("/ledoff", HTTP_GET, [] (AsyncWebServerRequest *request) { + //stopFastLed(); + + request->send(200, "text/plain", "LED OFF"); + }); + + // Start server + server.begin(); +} + + + + + +//The setup function is called once at startup of the sketch +void setup() { + Serial.begin(9600); + Serial.println(""); + + Wire.begin(); + pinMode(D4, OUTPUT); + randomSeed(analogRead(0)); + + if (connectWifi()) { + + // Init Panels + FastLed(); + //initAllPanels(); + + initWebService(); + + + } else { + digitalWrite(D4, LOW); + } +} + + + +// ------------ FINISH ----------------- +boolean connectWifi() { + boolean stat = true; + + // Connect to Wi-Fi + WiFi.config(ip, gateway, subnet); // uncomment for dynamic IP + WiFi.begin(ssid, password); + int count = 0; + while (WiFi.status() != WL_CONNECTED) { + count++; + digitalWrite(D4, LOW); + delay(1000); + digitalWrite(D4, HIGH); + Serial.println("Connecting to WiFi.."); + if (count == 10) { + stat = false; + break; + } + } + if (stat == true) { + digitalWrite(D4, LOW); + // Print ESP Local IP Address + Serial.println(WiFi.localIP()); + } + return stat; +} + +void FastLed() { + FastLED.addLeds(LEDsStatus, NUM_LEDS_1); + //FastLED.addLeds(LEDsPanel, NUM_LEDS_2); + FastLED.setBrightness(BRIGHTNESS); + +} + + + + + +// The loop function is called in an endless loop +void loop() { + + + if (variDemo == true && ledOn == 1) { + ledDemo(); + } + + //Fire2012(); // run simulation frame + + //FastLED.show(); // display this frame + //FastLED.delay(1000 / FRAMES_PER_SECOND); +} + +void stopLed() { + for (int panel = 0; panel < NUM_LEDS_1; panel++) { + LEDsStatus[panel] = CRGB::Black; + } + FastLED.show(); + + FastLED.clearData(); + FastLED.show(); + + FastLED.clear(); + FastLED.show(); +} + +void ledDemo() { + + LEDsStatus[0] = CRGB::Red; + FastLED.show(); + delay(500); + for (int panel = 0; panel < NUM_LEDS_1; panel++) { + LEDsStatus[panel] = CRGB::Yellow; + } + FastLED.show(); + delay(500); + for (int panel = 0; panel < NUM_LEDS_1; panel++) { + LEDsStatus[panel] = CRGB::Green; + } + for (int panel = 0; panel < NUM_LEDS_1; panel++) { + LEDsStatus[panel] = CRGB::Green; + } + FastLED.show(); + delay(500); + // Now turn the LED off, then pause + for (int panel = 0; panel < NUM_LEDS_1; panel++) { + LEDsStatus[panel] = CRGB::Black; + } + + FastLED.show(); + delay(500); +} + + +// SPARKING: What chance (out of 255) is there that a new spark will be lit? +// Higher chance = more roaring fire. Lower chance = more flickery fire. +// Default 120, suggested range 50-200. +#define SPARKING 120 + +void Fire2012() +{ +// Array of temperature readings at each simulation cell + static uint8_t heat[LED_PIN_1]; + + // Step 1. Cool down every cell a little + for( int i = 0; i < LED_PIN_1; i++) { + heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / LED_PIN_1) + 2)); + } + + // Step 2. Heat from each cell drifts 'up' and diffuses a little + for( int k= LED_PIN_1 - 1; k >= 2; k--) { + heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3; + } + + // Step 3. Randomly ignite new 'sparks' of heat near the bottom + if( random8() < SPARKING ) { + int y = random8(7); + heat[y] = qadd8( heat[y], random8(160,255) ); + } + + // Step 4. Map from heat cells to LED colors + for( int j = 0; j < LED_PIN_1; j++) { + CRGB color = HeatColor( heat[j]); + int pixelnumber; + if( gReverseDirection ) { + pixelnumber = (LED_PIN_1-1) - j; + } else { + pixelnumber = j; + } + Serial.print("Panel: "); + Serial.println(pixelnumber); + LEDsStatus[pixelnumber] = color; + } +} diff --git a/ledcontroler/spec.d b/ledcontroler/spec.d new file mode 100644 index 0000000..2f70fb7 --- /dev/null +++ b/ledcontroler/spec.d @@ -0,0 +1,2 @@ +spec.o: \ + C:/workspace/Arduino/.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.cpp