Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **LED Control**
- - Source Code NOT compiled for: Arduino Nano
- - Source Code created on: 2025-02-24 20:39:45
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Agregar otra secuencia de leds q donde 16 leds de */
- /* una tira led se prendan y apaguen en verde cada 5 */
- /* segundos solo si por comunicacion serial se */
- /* recibio un 2, si no se recibe solo activa la */
- /* primer secuencia */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Adafruit_NeoPixel.h> //https://github.com/adafruit/Adafruit_NeoPixel
- #include <FastLED.h> //https://github.com/FastLED/FastLED
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- void activateSecondSequence();
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t led_WS2812B_DIN_PIN_D2 = 2;
- #define LED_PIN 6 // This pin definition conflicts with the existing pin definition for WS2812B
- #define LED_COUNT 18
- #define MAX_INTENSITY 150
- #define NUM_LEDS_ON 4
- #define SECOND_SEQUENCE_LED_COUNT 16 // Number of LEDs in the second sequence
- #define SECOND_SEQUENCE_DELAY 5000 // Delay for the second sequence
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool led_WS2812B_DIN_PIN_D2_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float led_WS2812B_DIN_PIN_D2_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); // Initialize NeoPixel strip
- // Additional variables for the second LED sequence
- unsigned long previousMillis = 0; // Store the last time the second sequence was updated
- bool secondSequenceActive = false; // Flag to check if the second sequence should be active
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(led_WS2812B_DIN_PIN_D2, OUTPUT);
- strip.begin(); // Initialize the NeoPixel strip
- // Apagar todos los LEDs al inicio
- for (int i = 0; i < LED_COUNT; i++) {
- strip.setPixelColor(i, strip.Color(0, 0, 0));
- }
- delay(500);
- strip.show();
- for (int i = 0; i < LED_COUNT; i++) {
- if (i >= 4) {
- strip.setPixelColor(i, strip.Color(60, 30, 200));
- }
- }
- strip.show(); // Mostrar los cambios
- // Esperar un momento para que se apaguen todos los LEDs completamente
- delay(5000);
- Serial.begin(9600); // Start serial communication
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- // Check for serial input
- if (Serial.available() > 0) {
- int incomingByte = Serial.read();
- if (incomingByte == '2') {
- secondSequenceActive = true; // Activate second sequence if '2' is received
- } else {
- secondSequenceActive = false; // Deactivate second sequence for any other input
- }
- }
- // Handle the first LED sequence
- static int offset = 4; // Start at the fifth LED
- static int fadeValue = 0;
- static int direction = 1;
- // Encender los LEDs en el rango deseado
- for (int i = offset; i < offset + NUM_LEDS_ON; i++) {
- int index = i % LED_COUNT;
- if (index >= 4) { // Evitar encender los primeros cuatro LEDs al reiniciar la secuencia
- int brightness = (i == offset || i == offset + 5 || i == offset + 10 || i == offset + 15) ? MAX_INTENSITY : 0; // Encender solo ciertos LEDs
- strip.setPixelColor(index, strip.Color(0, brightness, 0));
- }
- }
- // Suavizado del cambio del Ășltimo LED al primero
- fadeValue += direction;
- if (fadeValue >= MAX_INTENSITY || fadeValue <= 0) {
- direction *= -1;
- }
- // Establecer la intensidad del Ășltimo LED
- if ((offset + NUM_LEDS_ON) % LED_COUNT >= 4) { // Evitar encender los primeros cuatro LEDs al reiniciar la secuencia
- strip.setPixelColor((offset + NUM_LEDS_ON) % LED_COUNT, strip.Color(0, fadeValue, 0));
- }
- strip.show();
- delay(50); // Ajusta este valor para la velocidad del desplazamiento
- // Actualizar el desplazamiento
- offset = (offset + 1) % LED_COUNT;
- // Handle the second LED sequence
- if (secondSequenceActive) {
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis >= SECOND_SEQUENCE_DELAY) {
- previousMillis = currentMillis; // Save the last time the second sequence was updated
- activateSecondSequence(); // Activate the second LED sequence
- }
- }
- }
- void updateOutputs()
- {
- digitalWrite(led_WS2812B_DIN_PIN_D2, led_WS2812B_DIN_PIN_D2_rawData);
- }
- void activateSecondSequence() {
- // Turn on the second sequence of LEDs in green
- for (int i = 0; i < SECOND_SEQUENCE_LED_COUNT; i++) {
- strip.setPixelColor(i, strip.Color(0, 255, 0)); // Set color to green
- }
- strip.show(); // Show the changes
- delay(SECOND_SEQUENCE_DELAY); // Keep them on for the defined delay
- // Turn off the second sequence
- for (int i = 0; i < SECOND_SEQUENCE_LED_COUNT; i++) {
- strip.setPixelColor(i, strip.Color(0, 0, 0)); // Turn off LEDs
- }
- strip.show(); // Show the changes
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement