1+ #include < Arduino.h>
2+ #include < Adafruit_NeoPixel.h>
3+ #include " ulp_lp_core.h"
4+ #include " esp_err.h"
5+
6+ // Define the built-in RGB LED pin and number of LEDs
7+ #define LED_PIN 8
8+ #define NUM_LEDS 1
9+
10+ Adafruit_NeoPixel rgbLed (NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
11+
12+ // Define some colors
13+ struct RGB {
14+ uint8_t r, g, b;
15+ };
16+
17+ constexpr RGB COLOR_RED = {255 , 0 , 0 };
18+ constexpr RGB COLOR_GREEN = {0 , 255 , 0 };
19+ constexpr RGB COLOR_BLUE = {0 , 0 , 255 };
20+ constexpr RGB COLOR_OFF = {0 , 0 , 0 };
21+
22+ extern const uint8_t bin_start[] asm (" _binary_ulp_main_bin_start" ); // refering to app name ulp_main defined in CMakelists.txt
23+ extern const uint8_t bin_end[] asm (" _binary_ulp_main_bin_end" ); // refering to app name ulp_main defined in CMakelists.txt
24+
25+ void start_ulp_program () {
26+ // Change: Load the ULP binary into RTC memory
27+ ESP_ERROR_CHECK (ulp_lp_core_load_binary (bin_start, (bin_end - bin_start)));
28+
29+ // Change: Configure the ULP LP core wake-up source and timer
30+ ulp_lp_core_cfg_t cfg = {
31+ .wakeup_source = ULP_LP_CORE_WAKEUP_SOURCE_LP_TIMER, // Wake up using LP timer
32+ .lp_timer_sleep_duration_us = 1000000 , // 1-second sleep duration
33+ };
34+
35+ // Change: Start the ULP LP core program
36+ ESP_ERROR_CHECK (ulp_lp_core_run (&cfg));
37+ }
38+
39+ void setColor (const RGB& color) {
40+ rgbLed.setPixelColor (0 , rgbLed.Color (color.r , color.g , color.b ));
41+ rgbLed.show ();
42+ }
43+
44+ void setup () {
45+ Serial.begin (115200 );
46+ Serial.println (" Starting ULP Program..." );
47+ start_ulp_program ();
48+ Serial.println (" Starting RGB LED blinking..." );
49+ rgbLed.begin (); // Initialize the NeoPixel library
50+ rgbLed.show (); // Turn off all LEDs initially
51+ }
52+
53+ void loop () {
54+ Serial.println (" Setting color to RED" );
55+ setColor (COLOR_RED);
56+ delay (1000 );
57+
58+ Serial.println (" Setting color to GREEN" );
59+ setColor (COLOR_GREEN);
60+ delay (1000 );
61+
62+ Serial.println (" Setting color to BLUE" );
63+ setColor (COLOR_BLUE);
64+ delay (1000 );
65+
66+ Serial.println (" Turning off LED" );
67+ setColor (COLOR_OFF);
68+ delay (1000 );
69+ }
0 commit comments