From 161352f0ca5728701cdd5506f8057c46eb54576b Mon Sep 17 00:00:00 2001 From: Daan Meijer Date: Wed, 15 Jan 2025 22:58:04 +0100 Subject: [PATCH] working led color cycling --- platformio.ini | 30 +++++++++++++++++++++++++++--- src/Hanglamp.cpp | 46 ++++++++++++++++++++++++++++++++++++++++------ src/Led.cpp | 6 +++--- src/Led.h | 4 ++-- src/MQTT.cpp | 2 ++ src/PinFinder.cpp | 16 ++++++++++------ src/Wifi.cpp | 3 +++ 7 files changed, 87 insertions(+), 20 deletions(-) diff --git a/platformio.ini b/platformio.ini index a8a49ef..2e93f19 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,6 +8,9 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +[platformio] +default_envs = esp32c3_supermini + [env:esp12e] platform = espressif8266 board = esp12e @@ -26,9 +29,30 @@ lib_deps = devyte/ESPAsyncDNSServer@^1.0.0 me-no-dev/ESPAsyncUDP makuna/NeoPixelBus @ ^2.8.0 - - lib_ldf_mode = chain+ -monitor_filters = default, esp8266_exception_decoder +monitor_filters = + default + esp8266_exception_decoder board_build.filesystem = littlefs board_build.f_cpu = 80000000L + +[env:esp32c3_supermini] +; platform = espressif32 +; board = esp32-c3-devkitm-1 + +; platform = https://github.com/Jason2866/platform-espressif32.git#Arduino/IDF5 +; board = lolin_c3_mini + +board = dfrobot_beetle_esp32c3 +platform = espressif32 +framework = arduino +monitor_speed = 460800 +lib_deps = + fastled/FastLED@^3.7.0 + +; [env:dfrobot_beetle_esp32c3] +; platform = espressif32 +; board = dfrobot_beetle_esp32c3 +; framework = arduino +; lib_deps = +; fastled/FastLED@^3.7.0 \ No newline at end of file diff --git a/src/Hanglamp.cpp b/src/Hanglamp.cpp index c5f1b6a..1619d60 100644 --- a/src/Hanglamp.cpp +++ b/src/Hanglamp.cpp @@ -1,4 +1,7 @@ +#define INCLUDE_LED +#ifdef INCLUDE_LED #include "Led.h" +#endif #include @@ -6,21 +9,32 @@ #define _TASK_STATUS_REQUEST // Compile with support for StatusRequest functionality - triggering tasks on status change events in addition to time only // #define ENABLE_MQTT -#define ENABLE_WIFI +// #define ENABLE_WIFI +// #define ENABLE_FS +// #define ENABLE_PINFINDER // #include +#ifdef ENABLE_MQTT #include "MQTT.h" -#include "Wifi.h" +#endif +#ifdef ENABLE_WIFI +#include "Wifi.h" +#endif + +#ifdef ENABLE_FS #include "FS.h" #include +#endif +#ifdef ENABLE_PINFINDER #include "PinFinder.h" +#endif void feedWatchdog(){ - ESP.wdtFeed(); + // ESP.wdtFeed(); } bool blinkStatus = false; @@ -29,6 +43,7 @@ void blink(){ digitalWrite(LED_BUILTIN, blinkStatus); } +#ifdef INCLUDE_LED CRGB colorTable[] = { CRGB::Red, CRGB::Blue, @@ -90,6 +105,7 @@ void colors(){ Serial.printf("colorIndex: %d\n", colorIndex); jumpTo(colorTable[colorIndex]); } +#endif void setup() { @@ -98,10 +114,12 @@ void setup() { delay(500); + #ifdef ENABLE_FS if(!LittleFS.begin()){ Serial.println("LittleFS Mount Failed"); return; } + #endif // runner.init(); @@ -115,17 +133,22 @@ void setup() { PinFinder_setup(); #endif + #ifdef INCLUDE_LED Led_setup(); jumpTo(CRGB(0xFF00FF)); + #endif #ifdef ENABLE_WIFI Wifi_setup(); #endif + #ifdef INCLUDE_LED jumpTo(CRGB(0x00FFFF)); jumpTo(CRGB(0x000000)); + #endif + #ifdef ENABLE_MQTT MQTT_setup(); #endif @@ -133,13 +156,16 @@ void setup() { OTA_setup(); #endif + #ifdef INCLUDE_LED jumpTo(CRGB(0x00FFFF)); + #endif // ESP.wdtEnable(10000); } void loop() { + #ifdef ENABLE_MQTT MQTT_loop(); #endif @@ -151,14 +177,19 @@ void loop() { #ifdef ENABLE_PINFINDER PinFinder_loop(); #endif - + + #ifdef INCLUDE_LED colors(); + #endif - delay(2000); + delay(1000); + + return; + + sleep(2000); // Led_loop(); - return; String command; @@ -174,6 +205,8 @@ void loop() { String name = command.substring(0, index); Serial.print("Have command name: "); Serial.println(name); + + #ifdef INCLUDE_LED if(name.equals("c")){ //c:0xff4000 //c:0xff0000 @@ -193,6 +226,7 @@ void loop() { jumpTo(target); } + #endif } } diff --git a/src/Led.cpp b/src/Led.cpp index 402ecb5..0cf787e 100644 --- a/src/Led.cpp +++ b/src/Led.cpp @@ -46,9 +46,9 @@ void displayLed(){ for(uint8_t index = 0; index < STRIP_LENGTH; index++){ // Serial.printf("Led 2:%02d 0x%02x%02x%02x\n", index, strip2[index].r, strip2[index].g, strip2[index].b); } - auto before = micros64(); + auto before = micros(); FastLED.show(); - auto after = micros64(); + auto after = micros(); Serial.printf("FastLED.show took %d micros\n", after - before); #endif @@ -116,7 +116,7 @@ void Led_setup(){ // analogWriteRange(255); #ifdef LED_FASTLED - // FastLED.addLeds(strip2, STRIP_LENGTH); + FastLED.addLeds(strip2, STRIP_LENGTH); FastLED.addLeds(strip2, STRIP_LENGTH); #endif diff --git a/src/Led.h b/src/Led.h index 0def5b7..9a7704f 100644 --- a/src/Led.h +++ b/src/Led.h @@ -20,8 +20,8 @@ #include #endif -#define PIN_STRIP1 4 -#define PIN_STRIP2 5 +#define PIN_STRIP1 3 +#define PIN_STRIP2 4 #define STRIP_LENGTH 46 diff --git a/src/MQTT.cpp b/src/MQTT.cpp index 8390dcd..9ec5902 100644 --- a/src/MQTT.cpp +++ b/src/MQTT.cpp @@ -1,3 +1,4 @@ +#ifdef ENABLE_MQTT #include "MQTT.h" #include @@ -115,3 +116,4 @@ void MQTT_loop(){ } client.loop(); } +#endif \ No newline at end of file diff --git a/src/PinFinder.cpp b/src/PinFinder.cpp index 583a66a..0ef3da5 100644 --- a/src/PinFinder.cpp +++ b/src/PinFinder.cpp @@ -4,14 +4,18 @@ char pins[] = { 0, + 1, 2, + 3, 4, 5, - 12, - 13, - 14, - 15, - 16, + 6, + 7, + 8, + 9, + 10, + 20, + 21, }; void PinFinder_setup(){ for(int index=0; index < sizeof(pins); index++){ @@ -26,7 +30,7 @@ void PinFinder_loop(){ auto pin = pins[index]; Serial.printf("Setting pin %d high\n", pin); digitalWrite(pin, HIGH); - delay(1000); + delay(100); Serial.printf("Setting pin %d low\n", pin); digitalWrite(pin, LOW); } diff --git a/src/Wifi.cpp b/src/Wifi.cpp index f18c69c..e052170 100644 --- a/src/Wifi.cpp +++ b/src/Wifi.cpp @@ -1,3 +1,5 @@ +#ifdef ENABLE_WIFI + #include #include @@ -40,3 +42,4 @@ void Wifi_setup(){ } +#endif \ No newline at end of file