vedderb / vesc_express

The source code for the VESC Express
GNU General Public License v3.0
38 stars 31 forks source link

Request for Example: Integrating Brake Signal with LED Control on ESP32-C3 #28

Open oangelo opened 4 months ago

oangelo commented 4 months ago

Hello VESC Express Team,

I've recently embarked on a journey to learn and experiment with VESC Express, starting with a DIY setup based on the ESP32-C3 Super Mini. As a beginner, I was hoping to find straightforward examples to kickstart my project, similar to the basic "blink" LED examples found in many development environments.

While I successfully implemented a simple LED blink program on GPIO 8, I'm aiming to delve into more complex scenarios. Specifically, I'm interested in controlling the LED (connected to GPIO 8 of the ESP32-C3) based on the brake signal's state, intending to turn on the LED whenever the brake is applied.

This functionality, I believe, would not only serve my learning curve but could also benefit others in the community, providing a practical example of integrating VESC's control signals with external hardware actions.

Below is the "blink" example I've managed to implement, which I'm sharing in the hopes it might assist someone else starting out:


;; Configure GPIO 8 as an output
(print "Start")
(gpio-configure 8 'pin-mode-out)
(gpio-write 8 1)

;; Define a recursive function to blink the LED without using `loop`
(defun blink-led ()(progn
  (gpio-write 8 1) ;; Turn LED on
  (print "led on")
  (sleep 1)     ;; Wait for 1000 milliseconds (1 second)
  (gpio-write 8 0) ;; Turn LED off
  (print "led off")
  (sleep 1)     ;; Wait for 1000 milliseconds (1 second)
  (blink-led)))     ;; Recursively call blink-led to continue the loop

;; Call the blink-led function to start blinking the LED
(blink-led)
oangelo commented 4 months ago

I am usig this hardware: https://forum.esk8.news/t/usb-c-to-vesc-can-forward-adapter-cheap-and-diy/79789