Problem while compling a WS2811 LED with ESP32

Hello guys, haven't worked with arduino ide for more than 5 years, i got this problem while trying to compile my code :

In file included from C:\Users\hatim\OneDrive\Bureau\rfid_ID_checker\Nanohex.h\Nanohex.h.ino:2:0:
C:\Users\hatim\OneDrive\Documents\Arduino\libraries\FastLED\src/FastLED.h:14:21: note: #pragma message: FastLED version 3.004.000

pragma message "FastLED version 3.004.000"

                 ^

In file included from C:\Users\hatim\OneDrive\Documents\Arduino\libraries\FastLED\src/FastLED.h:65:0,
from C:\Users\hatim\OneDrive\Bureau\rfid_ID_checker\Nanohex.h\Nanohex.h.ino:2:
C:\Users\hatim\OneDrive\Documents\Arduino\libraries\FastLED\src/fastspi.h:135:23: note: #pragma message: No hardware SPI pins defined. All SPI access will default to bitbanged output

pragma message "No hardware SPI pins defined. All SPI access will default to bitbanged output"

                   ^

C:\Users\hatim\AppData\Local\Temp\arduino_cache_311726\core\core_b0e1ab6f8a8a80946b8e9d6454e111a9.a(main.cpp.o):(.literal._Z8loopTaskPv+0x8): undefined reference to setup()' C:\Users\hatim\AppData\Local\Temp\arduino_cache_311726\core\core_b0e1ab6f8a8a80946b8e9d6454e111a9.a(main.cpp.o):(.literal._Z8loopTaskPv+0xc): undefined reference to loop()'
C:\Users\hatim\AppData\Local\Temp\arduino_cache_311726\core\core_b0e1ab6f8a8a80946b8e9d6454e111a9.a(main.cpp.o): In function loopTask(void*)': C:\Users\hatim\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\cores\esp32/main.cpp:18: undefined reference to setup()'
C:\Users\hatim\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\cores\esp32/main.cpp:21: undefined reference to `loop()'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board DOIT ESP32 DEVKIT V1.

Can one of you please help me find a solution?

Thank you guys

I'm terribly sorry to inform you that I am unable to piece together the code that is causing this error by looking at the error code.

It's, typically, good practice to post your well formatted code in code tags blah, blah, blah.

Just a shot in the dark..... I see Onedrive in your path. Are your files on the cloud? If so perhaps you might want to move them to local and give it a try.

Else I would separate all the parts of your code. For instance is there an example for the WS2811 in the library you are using?

thank you for your answer idahowalker, here is the code :

#include <stdint.h>
#include <FastLED.h>

/* Number of LEDs in each box/leaf */
#define LEDS_IN_BOX 13
/*The number of boxes */
#define NUM_BOXES 8
/*The pin the LED is connected to */
#define LED_PIN 19
/*Don't change unless you know what you're doing */
#define TOTAL_LEDS LEDS_IN_BOX *NUM_BOXES

CRGB leds[TOTAL_LEDS];

union FadeVector {
struct
{
float r;
float g;
float b;
};
struct
{
float h;
float s;
float v;
};
};

class Hexnode
{
private:
uint16_t ledStart;
uint16_t ledEnd;
uint16_t peakDelay;
uint16_t fadeTimeMs;
uint16_t pulseCount;
uint16_t numberOfPulses;
CRGB color;
CRGB colorTo;
CRGB colorAlt;
unsigned long startDrawTimer;
unsigned long lastDrawTimer;
unsigned long peakTimer;
bool animating;
bool pulsing;
FadeVector fadeVector;

public:
Hexnode(uint8_t index) : animating(false),
pulsing(false),
fadeTimeMs(1000),
numberOfPulses(0),
color(CRGB(0, 0, 0))

{
    ledStart = index * LEDS_IN_BOX;
    ledEnd = ledStart + LEDS_IN_BOX - 1;
}

void compute_fade_vector()
{
    fadeVector.r = (float)(colorTo.r - color.r) / (float)fadeTimeMs;
    fadeVector.g = (float)(colorTo.g - color.g) / (float)fadeTimeMs;
    fadeVector.b = (float)(colorTo.b - color.b) / (float)fadeTimeMs;
}

void set_color(CRGB c)
{
    colorTo = c;
    lastDrawTimer = millis();
    startDrawTimer = millis();
    animating = true;
    compute_fade_vector();
}

void set_static_color(CRGB c)
{
    pulsing = false;
    animating = false;
    color = c;
}
void start_pulse(CRGB to, CRGB from, uint16_t pDelay, uint16_t pSpeed, uint16_t count, bool force)
{
    if (!pulsing || force)
    {
        set_color(to);
        colorAlt = from;
        peakDelay = pDelay;
        fadeTimeMs = pSpeed;
        pulseCount = count;
        pulsing = true;
    }
}

void set_fade_time(uint16_t t)
{
    fadeTimeMs = t;
}

void color_update()
{
    unsigned long delta_ms = millis() - lastDrawTimer;
    lastDrawTimer = millis();
    int16_t r = color.r + (fadeVector.r * delta_ms);
    int16_t g = color.g + (fadeVector.g * delta_ms);
    int16_t b = color.b + (fadeVector.b * delta_ms);
    (r >= 255) ? color.r = 255 : (r <= 0) ? color.r = 0 : color.r = r;
    (g >= 255) ? color.g = 255 : (g <= 0) ? color.g = 0 : color.g = g;
    (b >= 255) ? color.b = 255 : (b <= 0) ? color.b = 0 : color.b = b;
}

int draw()
{
    if (pulsing && !animating)
    {
        if (millis() - peakTimer > peakDelay)
        {
            if (numberOfPulses == pulseCount)
            {
                pulsing = false;
                numberOfPulses = 0;
            }
            else
            {
                CRGB tmp = colorAlt;
                colorAlt = colorTo;
                set_color(tmp);
            }
        }
    }
    else if (animating)
    {
        color_update();
        if (millis() - startDrawTimer >= fadeTimeMs)
        {
            animating = false;
            peakTimer = millis();
        }
    }

    for (uint16_t ledPos = ledStart; ledPos <= ledEnd; ledPos++)
    {
        leds[ledPos] = color;
    }
    return 0;
}

};

class Nanohex
{
private:
Hexnode *nodes[NUM_BOXES];
uint16_t drawEveryNthMs;
unsigned long lastDrew;
unsigned long modeTimer;
CRGB primary;
CRGB secondary;
uint32_t fadeTimeMin;
uint32_t fadeTimeMax;
uint16_t mode;
uint8_t hueRandomness;
bool interrupt;

public:
Nanohex() : lastDrew(0),
modeTimer(0),
mode(1),
drawEveryNthMs(60),
primary(CRGB(0, 60, 120)),
secondary(CRGB(0, 0, 0)),
fadeTimeMin(3000),
fadeTimeMax(7000),
hueRandomness(50),
interrupt(false)
{
FastLED.addLeds<WS2812B, LED_PIN, BRG>(leds, TOTAL_LEDS);
for (uint8_t i = 0; i < NUM_BOXES; i++)
nodes[i] = new Hexnode(i);
}

void set_hue_randomness(uint8_t val)
{
    hueRandomness = val;
    interrupt = true;
}

void set_fadetime_min(uint32_t val)
{
    if (val > fadeTimeMax)
        val = fadeTimeMax;
    fadeTimeMin = val;
    Serial.printf("Minimum fade time %d s\n", (fadeTimeMin / 1000));
    interrupt = true;
}

void set_fadetime_max(uint32_t val)
{
    if (val < fadeTimeMin)
        val = fadeTimeMin;
    fadeTimeMax = val;
    Serial.printf("Maximum fade time %d s \n", (fadeTimeMax / 1000));
    interrupt = true;
}

void set_primary(CRGB c)
{
    modeTimer = 0;
    primary = c;
    interrupt = true;
}

void set_secondary(CRGB c)
{
    modeTimer = 0;
    secondary = c;
    interrupt = true;
}

void set_color_of(uint8_t idx, CRGB color)
{
    nodes[idx]->set_color(color);
}

void set_mode(uint8_t m)
{
    modeTimer = 0;
    mode = m;
}
void mode_static_color()
{
    for (uint8_t i = 0; i < NUM_BOXES; i++)
        nodes[i]->set_static_color(primary);
}

void mode_binary_twinkle()
{
    for (uint8_t i = 0; i < NUM_BOXES; i++)
        nodes[i]->start_pulse(primary, secondary, 300, random(fadeTimeMin, fadeTimeMax), 1, interrupt);

}

void mode_hue_twinkle() 
{
    CHSV c = rgb2hsv_approximate(primary);
    for (uint8_t i = 0; i < NUM_BOXES; i++)
    {
        CHSV color2 = CHSV(c.hue + random(-hueRandomness / 2, hueRandomness / 2), 255, 255);
        CHSV color1 = CHSV(c.hue + random(-hueRandomness / 2, hueRandomness / 2), c.sat, c.val);
        nodes[i]->start_pulse(color1, color2, 300, random(fadeTimeMin, fadeTimeMax), 1, interrupt);
    }
}

void update()
{
    if (millis() - modeTimer > 3000)
    {
        switch (mode)
        {
        case 1:
            mode_static_color();
            break;
        case 2:
            mode_binary_twinkle();
            break;
        case 3:
            mode_hue_twinkle();
            break;
        default:
            mode_static_color();
            break;
        }
        if (interrupt)
            interrupt = false;
        modeTimer = millis();
    }

    if (millis() - lastDrew > drawEveryNthMs)
    {
        for (uint8_t i = 0; i < NUM_BOXES; i++)
            int ret = nodes[i]->draw();
        FastLED.show();
        lastDrew = millis();
    }
}

void update_fade_time(uint16_t ms)
{
    for (uint8_t i = 0; i < NUM_BOXES; i++)
        nodes[i]->set_fade_time(ms);
}

void color_all(CRGB color)
{
    for (uint8_t i = 0; i < NUM_BOXES; i++)
        set_color_of(i, color);
}

};

i hope this can help you figuring out what my problem is

thanks guys

Great. Now post it properly using Code Tags. The instructions for doing so are in this article that you should have read before posting your question:

Please enclose the code in code tags.

The code is not complete. Please post all your code. Or come to understand why your code will not work under the Arduino IDE without setup() and loop() functions, as per the error message.

Thank you idahowalker for your response here is the code, i thought i already posted the whole code :sweat_smile:

#include <stdint.h>
#include <FastLED.h>

/* Number of LEDs in each box/leaf */
#define LEDS_IN_BOX 13
/*The number of boxes */
#define NUM_BOXES 8
/*The pin the LED is connected to */
#define LED_PIN 19
/*Don't change unless you know what you're doing */
#define TOTAL_LEDS LEDS_IN_BOX *NUM_BOXES

CRGB leds[TOTAL_LEDS];

union FadeVector {
    struct
    {
        float r;
        float g;
        float b;
    };
    struct
    {
        float h;
        float s;
        float v;
    };
};

class Hexnode
{
  private:
    uint16_t ledStart;
    uint16_t ledEnd;
    uint16_t peakDelay;
    uint16_t fadeTimeMs;
    uint16_t pulseCount;
    uint16_t numberOfPulses;
    CRGB color;
    CRGB colorTo;
    CRGB colorAlt;
    unsigned long startDrawTimer;
    unsigned long lastDrawTimer;
    unsigned long peakTimer;
    bool animating;
    bool pulsing;
    FadeVector fadeVector;

  public:
    Hexnode(uint8_t index) : animating(false),
                             pulsing(false),
                             fadeTimeMs(1000),
                             numberOfPulses(0),
                             color(CRGB(0, 0, 0))

    {
        ledStart = index * LEDS_IN_BOX;
        ledEnd = ledStart + LEDS_IN_BOX - 1;
    }

    void compute_fade_vector()
    {
        fadeVector.r = (float)(colorTo.r - color.r) / (float)fadeTimeMs;
        fadeVector.g = (float)(colorTo.g - color.g) / (float)fadeTimeMs;
        fadeVector.b = (float)(colorTo.b - color.b) / (float)fadeTimeMs;
    }

    void set_color(CRGB c)
    {
        colorTo = c;
        lastDrawTimer = millis();
        startDrawTimer = millis();
        animating = true;
        compute_fade_vector();
    }

    void set_static_color(CRGB c)
    {
        pulsing = false;
        animating = false;
        color = c;
    }
    void start_pulse(CRGB to, CRGB from, uint16_t pDelay, uint16_t pSpeed, uint16_t count, bool force)
    {
        if (!pulsing || force)
        {
            set_color(to);
            colorAlt = from;
            peakDelay = pDelay;
            fadeTimeMs = pSpeed;
            pulseCount = count;
            pulsing = true;
        }
    }

    void set_fade_time(uint16_t t)
    {
        fadeTimeMs = t;
    }

    void color_update()
    {
        unsigned long delta_ms = millis() - lastDrawTimer;
        lastDrawTimer = millis();
        int16_t r = color.r + (fadeVector.r * delta_ms);
        int16_t g = color.g + (fadeVector.g * delta_ms);
        int16_t b = color.b + (fadeVector.b * delta_ms);
        (r >= 255) ? color.r = 255 : (r <= 0) ? color.r = 0 : color.r = r;
        (g >= 255) ? color.g = 255 : (g <= 0) ? color.g = 0 : color.g = g;
        (b >= 255) ? color.b = 255 : (b <= 0) ? color.b = 0 : color.b = b;
    }

    int draw()
    {
        if (pulsing && !animating)
        {
            if (millis() - peakTimer > peakDelay)
            {
                if (numberOfPulses == pulseCount)
                {
                    pulsing = false;
                    numberOfPulses = 0;
                }
                else
                {
                    CRGB tmp = colorAlt;
                    colorAlt = colorTo;
                    set_color(tmp);
                }
            }
        }
        else if (animating)
        {
            color_update();
            if (millis() - startDrawTimer >= fadeTimeMs)
            {
                animating = false;
                peakTimer = millis();
            }
        }

        for (uint16_t ledPos = ledStart; ledPos <= ledEnd; ledPos++)
        {
            leds[ledPos] = color;
        }
        return 0;
    }
};

class Nanohex
{
  private:
    Hexnode *nodes[NUM_BOXES];
    uint16_t drawEveryNthMs;
    unsigned long lastDrew;
    unsigned long modeTimer;
    CRGB primary;
    CRGB secondary;
    uint32_t fadeTimeMin;
    uint32_t fadeTimeMax;
    uint16_t mode;
    uint8_t hueRandomness;
    bool interrupt;

  public:
    Nanohex() : lastDrew(0),
                modeTimer(0),
                mode(1),
                drawEveryNthMs(60),
                primary(CRGB(0, 60, 120)),
                secondary(CRGB(0, 0, 0)),
                fadeTimeMin(3000),
                fadeTimeMax(7000),
                hueRandomness(50),
                interrupt(false)
    {
        FastLED.addLeds<WS2812B, LED_PIN, BRG>(leds, TOTAL_LEDS);
        for (uint8_t i = 0; i < NUM_BOXES; i++)
            nodes[i] = new Hexnode(i);
    }

    void set_hue_randomness(uint8_t val)
    {
        hueRandomness = val;
        interrupt = true;
    }

    void set_fadetime_min(uint32_t val)
    {
        if (val > fadeTimeMax)
            val = fadeTimeMax;
        fadeTimeMin = val;
        Serial.printf("Minimum fade time %d s\n", (fadeTimeMin / 1000));
        interrupt = true;
    }

    void set_fadetime_max(uint32_t val)
    {
        if (val < fadeTimeMin)
            val = fadeTimeMin;
        fadeTimeMax = val;
        Serial.printf("Maximum fade time %d s \n", (fadeTimeMax / 1000));
        interrupt = true;
    }

    void set_primary(CRGB c)
    {
        modeTimer = 0;
        primary = c;
        interrupt = true;
    }

    void set_secondary(CRGB c)
    {
        modeTimer = 0;
        secondary = c;
        interrupt = true;
    }

    void set_color_of(uint8_t idx, CRGB color)
    {
        nodes[idx]->set_color(color);
    }

    void set_mode(uint8_t m)
    {
        modeTimer = 0;
        mode = m;
    }
    void mode_static_color()
    {
        for (uint8_t i = 0; i < NUM_BOXES; i++)
            nodes[i]->set_static_color(primary);
    }

    void mode_binary_twinkle()
    {
        for (uint8_t i = 0; i < NUM_BOXES; i++)
            nodes[i]->start_pulse(primary, secondary, 300, random(fadeTimeMin, fadeTimeMax), 1, interrupt);

    }

    void mode_hue_twinkle() 
    {
        CHSV c = rgb2hsv_approximate(primary);
        for (uint8_t i = 0; i < NUM_BOXES; i++)
        {
            CHSV color2 = CHSV(c.hue + random(-hueRandomness / 2, hueRandomness / 2), 255, 255);
            CHSV color1 = CHSV(c.hue + random(-hueRandomness / 2, hueRandomness / 2), c.sat, c.val);
            nodes[i]->start_pulse(color1, color2, 300, random(fadeTimeMin, fadeTimeMax), 1, interrupt);
        }
    }

    void update()
    {
        if (millis() - modeTimer > 3000)
        {
            switch (mode)
            {
            case 1:
                mode_static_color();
                break;
            case 2:
                mode_binary_twinkle();
                break;
            case 3:
                mode_hue_twinkle();
                break;
            default:
                mode_static_color();
                break;
            }
            if (interrupt)
                interrupt = false;
            modeTimer = millis();
        }

        if (millis() - lastDrew > drawEveryNthMs)
        {
            for (uint8_t i = 0; i < NUM_BOXES; i++)
                int ret = nodes[i]->draw();
            FastLED.show();
            lastDrew = millis();
        }
    }

    void update_fade_time(uint16_t ms)
    {
        for (uint8_t i = 0; i < NUM_BOXES; i++)
            nodes[i]->set_fade_time(ms);
    }

    void color_all(CRGB color)
    {
        for (uint8_t i = 0; i < NUM_BOXES; i++)
            set_color_of(i, color);
    }
};

Thanks john for your response. i just posted the whole code if you can try and figure out how i can solve my problem.

So, as has already been asked (at least twice), where is the setup() function? The loop() function?

Where is the setup() and loop() functions?

[quote="hatim97, post:1, topic:904005"] C:\Users\hatim\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\cores\esp32/main.cpp:18: undefined reference to `setup()'
[/quote]
You see in the 2 lines of error code the complaint of "WHERE IS setup()" and where is loop()?

I do not use loop() but i still have to include it under the Arduino IDE.

#include <WiFi.h>
#include <PubSubClient.h>
#include "certs.h"
#include "sdkconfig.h"
#include "esp32/ulp.h"
#include "driver/rtc_io.h"
#include "esp_system.h" //This inclusion configures the peripherals in the ESP system.
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/timers.h"
#include "freertos/event_groups.h"
#include <Adafruit_NeoPixel.h>
#include "AudioAnalyzer.h"
////
/* define event group and event bits */
EventGroupHandle_t eg;
#define evtDo_AudioReadFreq       ( 1 << 0 ) // 1
////
QueueHandle_t xQ_LED_Info;
////
//const int LED_COUNT = 24; //total number of leds in the strip
const int LED_COUNT = 108; //total number of leds in the strip
////
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
Adafruit_NeoPixel leds = Adafruit_NeoPixel( LED_COUNT, 26, NEO_GRB + NEO_KHZ800 );
//
WiFiClient wifiClient;
PubSubClient MQTTclient(mqtt_server, mqtt_port, wifiClient);
////
SemaphoreHandle_t sema_MQTT_KeepAlive;
////
void ULP_BLINK_RUN(uint32_t us);
////
void setup()
{
  ULP_BLINK_RUN(100000);
  eg = xEventGroupCreate();
  ////
  int FreqVal[7]; // used to set queue size
  xQ_LED_Info = xQueueCreate ( 1, sizeof(FreqVal) );
  ////
  sema_MQTT_KeepAlive = xSemaphoreCreateBinary();
  xSemaphoreGive( sema_MQTT_KeepAlive );
  ////
  // setting must be set before a mqtt connection is made
  MQTTclient.setKeepAlive( 90 ); // setting keep alive to 90 seconds
  connectToWiFi();
  connectToMQTT();
  //////////////////////////////////////////////////////////////////////////////////////////////
  xTaskCreatePinnedToCore( MQTTkeepalive, "MQTTkeepalive", 7000, NULL, 5, NULL, 1 );
  xTaskCreatePinnedToCore( fDo_AudioReadFreq, "fDo_ AudioReadFreq", 30000, NULL, 3, NULL, 1 );
  xTaskCreatePinnedToCore( fDo_LEDs, "fDo_ LEDs", 30000, NULL, 3, NULL, 1 );

  xEventGroupSetBits( eg, evtDo_AudioReadFreq );
} // setup()
////
void loop() {} // void loop
////
void fMQTT_Disconnect(  )
{
  MQTTclient.disconnect();
}
////
void GetTheTime()
{
  char* ntpServer = "2.us.pool.ntp.org";
  int gmtOffset_sec = -(3600 * 7 );
  int daylightOffset_sec = 3600;
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
  printLocalTime();
}
////
// http://www.cplusplus.com/reference/ctime/strftime/
////
void MQTTkeepalive( void *pvParameters )
{
  int keepCount = 0;
  for (;;)
  {
    log_i( " mqtt keep alive run." );

    if ( (wifiClient.connected()) && (WiFi.status() == WL_CONNECTED) )
    {
      //      xSemaphoreTake( sema_MQTT_KeepAlive, portMAX_DELAY ); //
      MQTTclient.loop();
      //      xSemaphoreGive( sema_MQTT_KeepAlive );
    }
    else {
      log_i( "MQTT keep alive found MQTT status %s WiFi status %s", String(wifiClient.connected()), String(WiFi.status()) );
      if ( !(WiFi.status() == WL_CONNECTED) )
      {
        connectToWiFi();
      }
      connectToMQTT();
    }
    vTaskDelay( 4900 );
    keepCount++;
    log_i( "%d", keepCount );
    if ( keepCount >= 5 )
    {
      fMQTT_Disconnect();
      keepCount = 0;
    }
  }
  vTaskDelete ( NULL );
}
////
int getHour()
{
  struct tm timeinfo;
  getLocalTime(&timeinfo);
  char _time[ 5 ];
  strftime( _time, 80, "%T", &timeinfo );
  return String(_time).toInt();
}
////
void printLocalTime() {
  struct tm timeinfo;
  getLocalTime(&timeinfo);
  char _time[ 80 ];
  strftime( _time, 80, "%T", &timeinfo );
  log_i( "%s", _time);
  //  }
}
////
void connectToMQTT()
{
  log_i( "connect to mqtt" );
  while ( !MQTTclient.connected() )
  {
    MQTTclient.connect( clientID, mqtt_username, mqtt_password );
    log_i( "connecting to MQTT" );
    vTaskDelay( 250 );
  }
  log_i("MQTT Connected");
  MQTTclient.setCallback( mqttCallback );
  MQTTclient.subscribe( mqtt_topic );
}
////
void connectToWiFi()
{
  log_i( " Begin Connect to wifi" );
  while ( WiFi.status() != WL_CONNECTED )
  {
    WiFi.disconnect();
    WiFi.begin( SSID, PASSWORD );
    log_i(" waiting on wifi connection" );
    vTaskDelay( 4000 );
  }
  log_i( "End connected to WiFi" );
  WiFi.onEvent( WiFiEvent );
  GetTheTime();
}
////
static void mqttCallback(char* topic, byte * payload, unsigned int length)
{

  //xSemaphoreTake( sema_MQTT_KeepAlive, portMAX_DELAY);
  //str_eTopicPtr = topic + '\0';

  int i = 0;
  String temp = "";
  for ( i; i < length; i++) {
    temp += ((char)payload[i]);
  }
  log_i( " topic %s payload %s", topic, temp );
  //  strPayloadPtr[i] = '\0';
  // xSemaphoreGive ( sema_MQTT_KeepAlive );
  //
} // void mqttCallback(char* topic, byte* payload, unsigned int length)
////
void fDo_LEDs( void *pvParameters )
{
  const int Brightness = 200;
  const int SEG = 6; // how many parts you want to separate the led strip into
  const int ledCount = LED_COUNT; //total number of leds in the strip
  int iFreqVal[7];
  int j;
  leds.begin(); // Call this to start up the LED strip.
  clearLEDs( ledCount );  // This function, defined below, de-energizes all LEDs...
  leds.show();  // ...but the LEDs don't actually update until you call this.
  leds.setBrightness( Brightness ); //  1 = min brightness (off), 255 = max brightness.
  for (;;)
  {
    if (xQueueReceive( xQ_LED_Info, &iFreqVal,  portMAX_DELAY) == pdTRUE)
    {
      j = 0;
      //assign different values for different parts of the led strip
      for (j = 0; j < ledCount; j++)
      {
        if ( (0 <= j) && (j < (ledCount / SEG)) )
        {
          //log_i( "segment 0 %d", iFreqVal[0] );
          set( j, iFreqVal[0], ledCount, SEG ); // set the color of led
        }
        else if ( ((ledCount / SEG) <= j) && (j < (ledCount / SEG * 2)) )
        {
          set( j, iFreqVal[0], ledCount, SEG );
        }
        else if ( ((ledCount / SEG * 2) <= j) && (j < (ledCount / SEG * 3)) )
        {
          set( j, iFreqVal[0], ledCount, SEG );
        }
        else if ( ((ledCount / SEG * 3) <= j) && (j < (ledCount / SEG * 4)) )
        {
          set( j, iFreqVal[0], ledCount, SEG );
        }
        else if ( ((ledCount / SEG * 4) <= j) && (j < (ledCount / SEG * 5)) )
        {
          set( j, iFreqVal[0], ledCount, SEG );
        }
        else
        {
          set( j, iFreqVal[0], ledCount, SEG );
        }
      }
      leds.show();
    }
    xEventGroupSetBits( eg, evtDo_AudioReadFreq );
  }
  vTaskDelete( NULL );
} // void fDo_ LEDs( void *pvParameters )
////
void fDo_AudioReadFreq( void *pvParameters )
{
  int FreqVal[7];
  const int NOISE = 10; // noise that you want to chop off
  const int A_D_ConversionBits = 4096; // arduino use 1024, ESP32 use 4096
  Analyzer Audio = Analyzer( 5, 15, 36 );//Strobe pin ->15  RST pin ->2 Analog Pin ->36
  Audio.Init(); // start the audio analyzer
  int64_t EndTime = esp_timer_get_time();
  int64_t StartTime = esp_timer_get_time(); //gets time in uSeconds like Arduino Micros
  for (;;)
  {
    xEventGroupWaitBits (eg, evtDo_AudioReadFreq, pdTRUE, pdTRUE, portMAX_DELAY);
    EndTime = esp_timer_get_time() - StartTime;
    // log_i( "TimeSpentOnTasks: %d", EndTime );
    Audio.ReadFreq(FreqVal);
    for (int i = 0; i < 7; i++)
    {
      FreqVal[i] = constrain( FreqVal[i], NOISE, A_D_ConversionBits );
      FreqVal[i] = map( FreqVal[i], NOISE, A_D_ConversionBits, 0, 255 );
      // log_i( "Freq %d Value: %d", i, FreqVal[i]);//used for debugging and Freq choosing
    }
    xQueueSend( xQ_LED_Info, ( void * ) &FreqVal, 0 );
    StartTime = esp_timer_get_time();
  }
  vTaskDelete( NULL );
} // fDo_ AudioReadFreq( void *pvParameters )
////
//the following function set the led color based on its position and freq value
//
void set(byte position, int value, int ledCount, int segment)
{
  int valueLowLimit = 20;
  // segment 0, red
  if ( (0 <= position) && (position < ledCount / segment) ) // segment 0 (bottom to top)
  {
    if ( value <= valueLowLimit )
    {
      leds.setPixelColor( position, 0, 0, 0 );
    }
    else
    {
      leds.setPixelColor( position, leds.Color( value , 0, 0) );
    }
  }
  else if ( (ledCount / segment <= position) && (position < ledCount / segment * 2) ) // segment 1 yellow
  {
    if ( value <= valueLowLimit )
    {
      leds.setPixelColor(position, leds.Color(0, 0, 0));
    }
    else
    {
      leds.setPixelColor(position, leds.Color( value, value, 0)); // works better to make yellow
    }
  }
  else if ( (ledCount / segment * 2 <= position) && (position < ledCount / segment * 3) ) // segment 2 pink
  {
    if ( value <= valueLowLimit )
    {
      leds.setPixelColor(position, leds.Color(0, 0, 0));
    }
    else
    {
      leds.setPixelColor(position, leds.Color( value, 0, value * .91) ); // pink
    }
  }
  else if ( (ledCount / segment * 3 <= position) && (position < ledCount / segment * 4) ) // seg 3, green
  {
    if ( value <= valueLowLimit )
    {
      leds.setPixelColor(position, leds.Color( 0, 0, 0));
    }
    else //
    {
      leds.setPixelColor( position, leds.Color( 0, value, 0) ); //
    }
  }
  else if ( (ledCount / segment * 4 <= position) && (position < ledCount / segment * 5) ) // segment 4, leds.color( R, G, B ), blue
  {
    if ( value <= valueLowLimit )
    {
      leds.setPixelColor(position, leds.Color( 0, 0, 0));
    }
    else //
    {
      leds.setPixelColor(position, leds.Color( 0, 0, value) ); // blue
    }
  }
  else // segment 5
  {
    if ( value <= valueLowLimit )
    {
      leds.setPixelColor(position, leds.Color( 0, 0, 0));
    }
    else
    {
      leds.setPixelColor( position, leds.Color( value, value * .3, 0) ); // orange
    }
  }
} // void set(byte position, int value)
////
void clearLEDs( int ledCount)
{
  for (int i = 0; i < ledCount; i++)
  {
    leds.setPixelColor(i, 0);
  }
} // void clearLEDs()
////
void WiFiEvent(WiFiEvent_t event)
{
  // log_i( "[WiFi-event] event: %d\n", event );
  switch (event)
  {
    case SYSTEM_EVENT_STA_CONNECTED:
      log_i("Connected to access point");
      break;
    case SYSTEM_EVENT_STA_DISCONNECTED:
      log_i("Disconnected from WiFi access point");
      break;
    case SYSTEM_EVENT_AP_STADISCONNECTED:
      log_i("WiFi client disconnected");
    default: break;
  }
}
//////////////////////////////////////////////
/*
  Each I_XXX preprocessor define translates into a single 32-bit instruction. So you can count instructions to learn which memory address are used and where the free mem space starts.

  To generate branch instructions, special M_ preprocessor defines are used. M_LABEL define can be used to define a branch target.
  Implementation note: these M_ preprocessor defines will be translated into two ulp_insn_t values: one is a token value which contains label number, and the other is the actual instruction.

*/
void ULP_BLINK_RUN(uint32_t us)
{
  size_t load_addr = 0;
  RTC_SLOW_MEM[12] = 0;
  ulp_set_wakeup_period(0, us);
  const ulp_insn_t  ulp_blink[] =
  {
    I_MOVI(R3, 12),                         // #12 -> R3
    I_LD(R0, R3, 0),                        // R0 = RTC_SLOW_MEM[R3(#12)]
    M_BL(1, 1),                             // GOTO M_LABEL(1) IF R0 < 1
    I_WR_REG(RTC_GPIO_OUT_REG, 26, 27, 1),  // RTC_GPIO2 = 1
    I_SUBI(R0, R0, 1),                      // R0 = R0 - 1, R0 = 1, R0 = 0
    I_ST(R0, R3, 0),                        // RTC_SLOW_MEM[R3(#12)] = R0
    M_BX(2),                                // GOTO M_LABEL(2)
    M_LABEL(1),                             // M_LABEL(1)
    I_WR_REG(RTC_GPIO_OUT_REG, 26, 27, 0),// RTC_GPIO2 = 0
    I_ADDI(R0, R0, 1),                    // R0 = R0 + 1, R0 = 0, R0 = 1
    I_ST(R0, R3, 0),                      // RTC_SLOW_MEM[R3(#12)] = R0
    M_LABEL(2),                             // M_LABEL(2)
    I_HALT()                                // HALT COPROCESSOR
  };
  const gpio_num_t led_gpios[] =
  {
    GPIO_NUM_2,
    // GPIO_NUM_0,
    // GPIO_NUM_4
  };
  for (size_t i = 0; i < sizeof(led_gpios) / sizeof(led_gpios[0]); ++i) {
    rtc_gpio_init(led_gpios[i]);
    rtc_gpio_set_direction(led_gpios[i], RTC_GPIO_MODE_OUTPUT_ONLY);
    rtc_gpio_set_level(led_gpios[i], 0);
  }
  size_t size = sizeof(ulp_blink) / sizeof(ulp_insn_t);
  ulp_process_macros_and_load( load_addr, ulp_blink, &size);
  ulp_run( load_addr );
} // void ULP_BLINK_RUN(uint32_t us)
//////////////////////////////////////////////

WHERE IS THE setup() and loop() functions?

My suggestion was to try an example file that most likely came with the library. Use the example to verify the hardware and library are working.

From that point you can start to add you custom code, one function at at time.

From what others have noticed, your program structure in not complete. Assuming you copied the code from elsewhere, you should go back to that resource and recopy the code.

Thank you john, yes i actually copied the code from a youtube guy : here's the link to his code that seems to be working for others but not me : Natural-Nerd/Nanohex.h at 041ed6bed7bafc23a8fbaa6193bbec879d059620 · hansjny/Natural-Nerd · GitHub

I don't know what i am missing

Are you FREAKING KIDDING? Or just a troll? setup() and loop()

PLEASE, follow this suggestion:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.