working led color cycling

This commit is contained in:
Daan Meijer 2025-01-15 22:58:04 +01:00
parent 9f889cd1a9
commit 161352f0ca
7 changed files with 87 additions and 20 deletions

View File

@ -8,6 +8,9 @@
; Please visit documentation for the other options and examples ; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[platformio]
default_envs = esp32c3_supermini
[env:esp12e] [env:esp12e]
platform = espressif8266 platform = espressif8266
board = esp12e board = esp12e
@ -26,9 +29,30 @@ lib_deps =
devyte/ESPAsyncDNSServer@^1.0.0 devyte/ESPAsyncDNSServer@^1.0.0
me-no-dev/ESPAsyncUDP me-no-dev/ESPAsyncUDP
makuna/NeoPixelBus @ ^2.8.0 makuna/NeoPixelBus @ ^2.8.0
lib_ldf_mode = chain+ lib_ldf_mode = chain+
monitor_filters = default, esp8266_exception_decoder monitor_filters =
default
esp8266_exception_decoder
board_build.filesystem = littlefs board_build.filesystem = littlefs
board_build.f_cpu = 80000000L 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

View File

@ -1,4 +1,7 @@
#define INCLUDE_LED
#ifdef INCLUDE_LED
#include "Led.h" #include "Led.h"
#endif
#include <Arduino.h> #include <Arduino.h>
@ -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 _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_MQTT
#define ENABLE_WIFI // #define ENABLE_WIFI
// #define ENABLE_FS
// #define ENABLE_PINFINDER
// #include <TaskScheduler.h> // #include <TaskScheduler.h>
#ifdef ENABLE_MQTT
#include "MQTT.h" #include "MQTT.h"
#include "Wifi.h" #endif
#ifdef ENABLE_WIFI
#include "Wifi.h"
#endif
#ifdef ENABLE_FS
#include "FS.h" #include "FS.h"
#include <LittleFS.h> #include <LittleFS.h>
#endif
#ifdef ENABLE_PINFINDER
#include "PinFinder.h" #include "PinFinder.h"
#endif
void feedWatchdog(){ void feedWatchdog(){
ESP.wdtFeed(); // ESP.wdtFeed();
} }
bool blinkStatus = false; bool blinkStatus = false;
@ -29,6 +43,7 @@ void blink(){
digitalWrite(LED_BUILTIN, blinkStatus); digitalWrite(LED_BUILTIN, blinkStatus);
} }
#ifdef INCLUDE_LED
CRGB colorTable[] = { CRGB colorTable[] = {
CRGB::Red, CRGB::Red,
CRGB::Blue, CRGB::Blue,
@ -90,6 +105,7 @@ void colors(){
Serial.printf("colorIndex: %d\n", colorIndex); Serial.printf("colorIndex: %d\n", colorIndex);
jumpTo(colorTable[colorIndex]); jumpTo(colorTable[colorIndex]);
} }
#endif
void setup() { void setup() {
@ -98,10 +114,12 @@ void setup() {
delay(500); delay(500);
#ifdef ENABLE_FS
if(!LittleFS.begin()){ if(!LittleFS.begin()){
Serial.println("LittleFS Mount Failed"); Serial.println("LittleFS Mount Failed");
return; return;
} }
#endif
// runner.init(); // runner.init();
@ -115,17 +133,22 @@ void setup() {
PinFinder_setup(); PinFinder_setup();
#endif #endif
#ifdef INCLUDE_LED
Led_setup(); Led_setup();
jumpTo(CRGB(0xFF00FF)); jumpTo(CRGB(0xFF00FF));
#endif
#ifdef ENABLE_WIFI #ifdef ENABLE_WIFI
Wifi_setup(); Wifi_setup();
#endif #endif
#ifdef INCLUDE_LED
jumpTo(CRGB(0x00FFFF)); jumpTo(CRGB(0x00FFFF));
jumpTo(CRGB(0x000000)); jumpTo(CRGB(0x000000));
#endif
#ifdef ENABLE_MQTT #ifdef ENABLE_MQTT
MQTT_setup(); MQTT_setup();
#endif #endif
@ -133,13 +156,16 @@ void setup() {
OTA_setup(); OTA_setup();
#endif #endif
#ifdef INCLUDE_LED
jumpTo(CRGB(0x00FFFF)); jumpTo(CRGB(0x00FFFF));
#endif
// ESP.wdtEnable(10000); // ESP.wdtEnable(10000);
} }
void loop() { void loop() {
#ifdef ENABLE_MQTT #ifdef ENABLE_MQTT
MQTT_loop(); MQTT_loop();
#endif #endif
@ -151,14 +177,19 @@ void loop() {
#ifdef ENABLE_PINFINDER #ifdef ENABLE_PINFINDER
PinFinder_loop(); PinFinder_loop();
#endif #endif
#ifdef INCLUDE_LED
colors(); colors();
#endif
delay(2000); delay(1000);
return;
sleep(2000);
// Led_loop(); // Led_loop();
return;
String command; String command;
@ -174,6 +205,8 @@ void loop() {
String name = command.substring(0, index); String name = command.substring(0, index);
Serial.print("Have command name: "); Serial.print("Have command name: ");
Serial.println(name); Serial.println(name);
#ifdef INCLUDE_LED
if(name.equals("c")){ if(name.equals("c")){
//c:0xff4000 //c:0xff4000
//c:0xff0000 //c:0xff0000
@ -193,6 +226,7 @@ void loop() {
jumpTo(target); jumpTo(target);
} }
#endif
} }
} }

View File

@ -46,9 +46,9 @@ void displayLed(){
for(uint8_t index = 0; index < STRIP_LENGTH; index++){ 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); // 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(); FastLED.show();
auto after = micros64(); auto after = micros();
Serial.printf("FastLED.show took %d micros\n", after - before); Serial.printf("FastLED.show took %d micros\n", after - before);
#endif #endif
@ -116,7 +116,7 @@ void Led_setup(){
// analogWriteRange(255); // analogWriteRange(255);
#ifdef LED_FASTLED #ifdef LED_FASTLED
// FastLED.addLeds<WS2812B, PIN_STRIP1>(strip2, STRIP_LENGTH); FastLED.addLeds<WS2812B, PIN_STRIP1>(strip2, STRIP_LENGTH);
FastLED.addLeds<WS2812B, PIN_STRIP2>(strip2, STRIP_LENGTH); FastLED.addLeds<WS2812B, PIN_STRIP2>(strip2, STRIP_LENGTH);
#endif #endif

View File

@ -20,8 +20,8 @@
#include <NeoPixelBus.h> #include <NeoPixelBus.h>
#endif #endif
#define PIN_STRIP1 4 #define PIN_STRIP1 3
#define PIN_STRIP2 5 #define PIN_STRIP2 4
#define STRIP_LENGTH 46 #define STRIP_LENGTH 46

View File

@ -1,3 +1,4 @@
#ifdef ENABLE_MQTT
#include "MQTT.h" #include "MQTT.h"
#include <PubSubClient.h> #include <PubSubClient.h>
@ -115,3 +116,4 @@ void MQTT_loop(){
} }
client.loop(); client.loop();
} }
#endif

View File

@ -4,14 +4,18 @@
char pins[] = { char pins[] = {
0, 0,
1,
2, 2,
3,
4, 4,
5, 5,
12, 6,
13, 7,
14, 8,
15, 9,
16, 10,
20,
21,
}; };
void PinFinder_setup(){ void PinFinder_setup(){
for(int index=0; index < sizeof(pins); index++){ for(int index=0; index < sizeof(pins); index++){
@ -26,7 +30,7 @@ void PinFinder_loop(){
auto pin = pins[index]; auto pin = pins[index];
Serial.printf("Setting pin %d high\n", pin); Serial.printf("Setting pin %d high\n", pin);
digitalWrite(pin, HIGH); digitalWrite(pin, HIGH);
delay(1000); delay(100);
Serial.printf("Setting pin %d low\n", pin); Serial.printf("Setting pin %d low\n", pin);
digitalWrite(pin, LOW); digitalWrite(pin, LOW);
} }

View File

@ -1,3 +1,5 @@
#ifdef ENABLE_WIFI
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <ESPAsync_WiFiManager.h> #include <ESPAsync_WiFiManager.h>
@ -40,3 +42,4 @@ void Wifi_setup(){
} }
#endif