Use onboard LED
This commit is contained in:
@@ -11,6 +11,9 @@ framework = arduino
|
||||
build_flags =
|
||||
-D ARDUINO_USB_MODE=1
|
||||
-D ARDUINO_USB_CDC_ON_BOOT=1
|
||||
-D STATUS_LED_PIN=8
|
||||
-D STATUS_LED_ON=LOW
|
||||
-D STATUS_LED_OFF=HIGH
|
||||
|
||||
board_upload.flash_size = 4MB
|
||||
board_build.flash_mode = dio
|
||||
|
||||
@@ -90,6 +90,21 @@ enum HomingState {
|
||||
};
|
||||
HomingState homingState = HOME_IDLE;
|
||||
|
||||
// ─── LED globals ──────────────────────────────────────────────────
|
||||
#ifndef STATUS_LED_PIN
|
||||
#ifdef LED_BUILTIN
|
||||
#define STATUS_LED_PIN LED_BUILTIN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef STATUS_LED_ON
|
||||
#define STATUS_LED_ON HIGH
|
||||
#define STATUS_LED_OFF LOW
|
||||
#endif
|
||||
|
||||
unsigned long lastBlinkTime = 0;
|
||||
bool ledState = false;
|
||||
|
||||
// ─── Forward declarations ─────────────────────────────────────────
|
||||
void parseCommand(const String &cmd);
|
||||
void sendPosition();
|
||||
@@ -247,6 +262,11 @@ void setup() {
|
||||
delay(1000); // Wait for USB CDC to enumerate
|
||||
Serial.println("\n[BOOT] WijiBoard Stepper Controller");
|
||||
|
||||
#ifdef STATUS_LED_PIN
|
||||
pinMode(STATUS_LED_PIN, OUTPUT);
|
||||
digitalWrite(STATUS_LED_PIN, STATUS_LED_OFF);
|
||||
#endif
|
||||
|
||||
// ── Init steppers ──────────────────────────────────────────
|
||||
stepper1.setMaxSpeed(DEFAULT_SPEED);
|
||||
stepper1.setAcceleration(DEFAULT_ACCEL);
|
||||
@@ -366,6 +386,28 @@ void loop() {
|
||||
sendPosition();
|
||||
}
|
||||
}
|
||||
|
||||
// LED state management
|
||||
#ifdef STATUS_LED_PIN
|
||||
if (moving) {
|
||||
unsigned long now = millis();
|
||||
if (now - lastBlinkTime >= 150) { // 150ms blink interval
|
||||
lastBlinkTime = now;
|
||||
ledState = !ledState;
|
||||
digitalWrite(STATUS_LED_PIN, ledState ? STATUS_LED_ON : STATUS_LED_OFF);
|
||||
}
|
||||
} else if (bleConnected) {
|
||||
if (!ledState) {
|
||||
digitalWrite(STATUS_LED_PIN, STATUS_LED_ON);
|
||||
ledState = true;
|
||||
}
|
||||
} else {
|
||||
if (ledState) {
|
||||
digitalWrite(STATUS_LED_PIN, STATUS_LED_OFF);
|
||||
ledState = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// ─── Homing Routines ──────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user