Advertisement
microrobotics

ESP32-S3-N16R8_Interface_LED's

Jun 4th, 2024
3,028
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_NeoPixel.h>
  2.  
  3. // Define the pins for the LEDs
  4. #define LED_TX_PIN 43
  5. #define LED_RX_PIN 44
  6. #define RGB_LED_PIN 48
  7.  
  8. // Define the number of RGB LEDs (assuming 1 WS2812 LED)
  9. #define NUM_RGB_LEDS 1
  10.  
  11. // Create an instance of the Adafruit_NeoPixel class
  12. Adafruit_NeoPixel rgb_led = Adafruit_NeoPixel(NUM_RGB_LEDS, RGB_LED_PIN, NEO_GRB + NEO_KHZ800);
  13.  
  14. void setup() {
  15.   // Initialize the serial communication
  16.   Serial.begin(115200);
  17.  
  18.   // Initialize the LED pins
  19.   pinMode(LED_TX_PIN, OUTPUT);
  20.   pinMode(LED_RX_PIN, OUTPUT);
  21.  
  22.   // Initialize the RGB LED
  23.   rgb_led.begin();
  24.   rgb_led.show(); // Initialize all pixels to 'off'
  25.  
  26.   // Start a test sequence
  27.   Serial.println("Starting LED test sequence...");
  28. }
  29.  
  30. void loop() {
  31.   // Blink the TX LED
  32.   digitalWrite(LED_TX_PIN, HIGH);
  33.   delay(500);
  34.   digitalWrite(LED_TX_PIN, LOW);
  35.   delay(500);
  36.  
  37.   // Blink the RX LED
  38.   digitalWrite(LED_RX_PIN, HIGH);
  39.   delay(500);
  40.   digitalWrite(LED_RX_PIN, LOW);
  41.   delay(500);
  42.  
  43.   // Test the RGB LED
  44.   testRGBLED();
  45. }
  46.  
  47. void testRGBLED() {
  48.   // Set RGB LED to red
  49.   rgb_led.setPixelColor(0, rgb_led.Color(255, 0, 0)); // Red
  50.   rgb_led.show();
  51.   delay(500);
  52.  
  53.   // Set RGB LED to green
  54.   rgb_led.setPixelColor(0, rgb_led.Color(0, 255, 0)); // Green
  55.   rgb_led.show();
  56.   delay(500);
  57.  
  58.   // Set RGB LED to blue
  59.   rgb_led.setPixelColor(0, rgb_led.Color(0, 0, 255)); // Blue
  60.   rgb_led.show();
  61.   delay(500);
  62.  
  63.   // Turn off the RGB LED
  64.   rgb_led.setPixelColor(0, rgb_led.Color(0, 0, 0)); // Off
  65.   rgb_led.show();
  66.   delay(500);
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement