/********* 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: 2024-09-15 01:07:05 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* buat animasi sein kiri kanan dan hazard dengan */ /* memakai input D2 D3 D4 sebagai trigger untuk */ /* aktivasi dengan menggunakan ledstrip ws2812b */ /* sebanyak 24 led */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include //https://github.com/evert-arias/EasyButton #include //https://github.com/FastLED/FastLED /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t tombolkiri_PushButton_PIN_D2 = 2; // Left signal button const uint8_t tombolkanan_PushButton_PIN_D3 = 3; // Right signal button const uint8_t tombolhazard_PushButton_PIN_D4 = 4; // Hazard button /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ // Instantiate EasyButton objects for each button EasyButton tombolkiriButton(tombolkiri_PushButton_PIN_D2); EasyButton tombolkananButton(tombolkanan_PushButton_PIN_D3); EasyButton tombolhazardButton(tombolhazard_PushButton_PIN_D4); // Define the number of LEDs and the data pin for FastLED #define NUM_LEDS 24 // Set to 24 LEDs as per the requirement #define DATA_PIN 5 // Instantiate the LED array CRGB leds[NUM_LEDS]; /****** FUNCTION DEFINITIONS *****/ void setup(void) { // Initialize serial communication for debugging Serial.begin(115200); // Set button pins as input with pull-up resistors pinMode(tombolkiri_PushButton_PIN_D2, INPUT_PULLUP); pinMode(tombolkanan_PushButton_PIN_D3, INPUT_PULLUP); pinMode(tombolhazard_PushButton_PIN_D4, INPUT_PULLUP); // Initialize the EasyButton instances tombolkiriButton.begin(); tombolkananButton.begin(); tombolhazardButton.begin(); // Initialize the FastLED library FastLED.addLeds(leds, NUM_LEDS); // Initialize the LED strip FastLED.setBrightness(84); // Set the brightness of the LEDs } void loop(void) { // Read the state of the buttons tombolkiriButton.read(); tombolkananButton.read(); tombolhazardButton.read(); // Check for left signal button press if (tombolkiriButton.isPressed()) { for (int i = 0; i < NUM_LEDS; i++) { leds[i] = CRGB::Red; // Set all LEDs to red for left signal } FastLED.show(); // Update the LED strip delay(500); // Delay to simulate blinking effect for (int i = 0; i < NUM_LEDS; i++) { leds[i] = CRGB::Black; // Turn off LEDs } FastLED.show(); // Update the LED strip delay(500); // Delay to simulate blinking effect } // Check for right signal button press else if (tombolkananButton.isPressed()) { for (int i = 0; i < NUM_LEDS; i++) { leds[i] = CRGB::Green; // Set all LEDs to green for right signal } FastLED.show(); // Update the LED strip delay(500); // Delay to simulate blinking effect for (int i = 0; i < NUM_LEDS; i++) { leds[i] = CRGB::Black; // Turn off LEDs } FastLED.show(); // Update the LED strip delay(500); // Delay to simulate blinking effect } // Check for hazard button press else if (tombolhazardButton.isPressed()) { for (int i = 0; i < NUM_LEDS; i++) { leds[i] = CRGB::Blue; // Set all LEDs to blue for hazard } FastLED.show(); // Update the LED strip delay(500); // Delay to simulate blinking effect for (int i = 0; i < NUM_LEDS; i++) { leds[i] = CRGB::Black; // Turn off LEDs } FastLED.show(); // Update the LED strip delay(500); // Delay to simulate blinking effect } } /* END CODE */