Skip to content

Commit 0c767e5

Browse files
committed
Drafted/started RGB Status LED code
1 parent 390d99d commit 0c767e5

3 files changed

Lines changed: 52 additions & 4 deletions

File tree

include/CommonConfig.hpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#pragma once
2+
3+
static_assert(__cplusplus >= 202302L,
4+
"C++23 standard or later required.");
5+
6+
// Imports
7+
#include <cstdint>
8+
9+
// CommonConfig.hpp
10+
11+
// MARK: Boards
12+
namespace UM_PROS3 {
13+
constexpr uint_fast8_t LED_DATA_PIN = 18;
14+
} // namespace UM_PROS3
15+
16+
// MARK: Constants
17+
namespace CONSTS {
18+
constexpr uint32_t MILLIS_PER_SEC = 1000;
19+
constexpr uint32_t SECS_PER_MIN = 60;
20+
} // namespace CONSTS
21+
22+
// Mark: Application
23+
namespace LED {
24+
/**
25+
* @see
26+
* https://wiki.dfrobot.com/SKU_DFR1075_FireBeetle_2_Board_ESP32_C6#5.2%20LED%20Blinking
27+
*/
28+
constexpr uint_fast8_t LED_DATA_PIN = UM_PROS3::LED_DATA_PIN;
29+
constexpr uint32_t BLINK_OFF_SECS = 3;
30+
constexpr uint32_t BLINK_OFF_MILLIS =
31+
BLINK_OFF_SECS * CONSTS::MILLIS_PER_SEC;
32+
// constexpr uint32_t LED_BLINK_ON_SEC = 1;
33+
constexpr uint32_t BLINK_ON_MILLIS = CONSTS::MILLIS_PER_SEC / 3;
34+
35+
} // namespace LED
36+
37+
namespace RUN {
38+
constexpr uint32_t SLEEP_TIME_MINS = 10;
39+
constexpr uint32_t SLEEP_TIME_SECS = SLEEP_TIME_MINS * CONSTS::SECS_PER_MIN;
40+
constexpr uint32_t SLEEP_TIME_MILLIS =
41+
SLEEP_TIME_SECS * CONSTS::MILLIS_PER_SEC;
42+
} // namespace RUN

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ monitor_filters = log2file, esp32_exception_decoder
1919
lib_deps =
2020
adafruit/Adafruit BusIO @ ^1.17.4
2121
adafruit/Adafruit INA260 Library @ ^1.5.3
22+
adafruit/Adafruit NeoPixel @ ^1.15.2
2223
etlcpp/Embedded Template Library @ ^20.44.1
2324
; https://techoverflow.net/2021/12/14/how-to-print-all-preprocessor-flags-in-platformio/
2425
; build_flags = -O3 -std=gnu++23 -Wall -E -dM

src/main.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
/* Includes */
66
#include "2026Core/Net/Net-Link/AdapterUHCI.hpp"
77
// #include "2026Core/Net/NetAdapter_A.hpp"
8+
#include "CommonConfig.hpp"
89
#include "esp_log.h"
10+
#include <Adafruit_NeoPixel.h>
911
#include <Arduino.h>
1012
#include "MCP23008T.hpp"
1113

@@ -14,6 +16,7 @@ static constexpr char *TAG = "LoMa";
1416
static constexpr uint8_t LOAD_ADDR = 0x00; // I2C address
1517

1618
/* Global Objects */
19+
Adafruit_NeoPixel leds(1, UM_PROS3::LED_DATA_PIN, NEO_GRB + NEO_KHZ800);
1720
MCP23008T loadDevice(LOAD_ADDR, &Wire);
1821
bool loadConfigured = false;
1922

@@ -51,9 +54,11 @@ bool configureLoad() {
5154
* put your setup code here, to run once:
5255
*/
5356
void setup() {
54-
pinMode(LED::LED_PIN, OUTPUT);
55-
5657
// Configure Devices
58+
if (!leds.begin()) {
59+
ESP_LOGE(TAG, "Failed to initialize LED");
60+
leds.setPixelColor(0, 0xFF, 0xA5, 0x00); // Orange
61+
}
5762
loadConfigured = configureLoad();
5863

5964
// Set up tasks
@@ -76,9 +81,9 @@ void setup() {
7681

7782
void vTaskStatusLED(void *pvParameters) {
7883
while (true) {
79-
digitalWrite(LED::LED_PIN, HIGH);
84+
leds.setPixelColor(0, 0x00, 0xFF, 0x00); // Green
8085
delay(LED::BLINK_ON_MILLIS);
81-
digitalWrite(LED::LED_PIN, LOW);
86+
leds.clear();
8287
delay(LED::BLINK_OFF_MILLIS);
8388
}
8489
}

0 commit comments

Comments
 (0)