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: "Color Toggle"
- - Source Code NOT compiled for: Arduino Pro Mini 5V
- - Source Code created on: 2025-06-10 17:48:56
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* when button is pressed led most change color from */
- /* red to white */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <FastLED.h> //https://github.com/FastLED/FastLED
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t ws_WS2812_DIN_PIN_D2 = 2;
- #define DATA_PIN 5 // This defines the data pin for FastLED
- //#define CLK_PIN 4 // CLK_PIN is not used in this setup, so it is commented out
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool ws_WS2812_DIN_PIN_D2_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float ws_WS2812_DIN_PIN_D2_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- CRGB leds[NUM_LEDS]; // Declare the array of LEDs
- byte ledIndex[NUM_LEDS] = {2}; // LED index array
- #define BRIGHTNESS 96
- #define FRAMES_PER_SECOND 120
- byte ch1Hue = 135;
- byte maxHue = 240;
- // Define button pin
- const int BUTTON_PIN = 3; // Assuming the button is connected to pin 3
- bool ledColorState = false; // false for red, true for white
- /****** FUNCTION PROTOTYPES FOR USER CODE *****/
- void potentiometers();
- void channelMenu();
- void setAllLeds(byte hue_, byte randomness_);
- void updateLedColor(); // Function to update LED color based on button press
- /****** SETUP FUNCTION *****/
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(ws_WS2812_DIN_PIN_D2, OUTPUT);
- pinMode(BUTTON_PIN, INPUT_PULLUP); // Initialize button pin
- // FastLED setup
- FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(BRIGHTNESS);
- setAllLeds(ch1Hue, 30); // set all leds at once with a hue (hue, randomness)
- FastLED.show();
- // Initialize buttons with pull up resistors
- for (int i = 0; i < N_BUTTONS_ARDUINO; i++) {
- pinMode(BUTTON_ARDUINO_PIN[i], INPUT_PULLUP);
- }
- pinMode(CHANNEL_BUTTON_PIN, INPUT_PULLUP);
- // Initialize pots with pull up resistors
- for (int i = 0; i < N_POTS_ARDUINO; i++) {
- pinMode(POT_ARDUINO_PIN[i], INPUT_PULLUP);
- }
- // Setup threads for potentiometers and channel menu
- threadPotentiometers.setInterval(15);
- threadPotentiometers.onRun(potentiometers);
- threadChannelMenu.setInterval(40);
- threadChannelMenu.onRun(channelMenu);
- cpu.add(&threadPotentiometers);
- cpu.add(&threadChannelMenu);
- }
- /****** LOOP FUNCTION *****/
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- MIDIread();
- buttons();
- cpu.run(); // for threads
- // Update LED color based on button press
- updateLedColor();
- // FastLED.show(); // Uncomment if you want to show LEDs in loop
- // insert a delay to keep the framerate modest
- // FastLED.delay(1000 / FRAMES_PER_SECOND);
- }
- void updateOutputs()
- {
- digitalWrite(ws_WS2812_DIN_PIN_D2, ws_WS2812_DIN_PIN_D2_rawData);
- }
- void updateLedColor() {
- if (digitalRead(BUTTON_PIN) == LOW) { // Button pressed
- ledColorState = !ledColorState; // Toggle color state
- if (ledColorState) {
- setAllLeds(255, 0); // Set to white
- } else {
- setAllLeds(255, 0, 0); // Set to red
- }
- FastLED.show(); // Update LED display
- delay(200); // Debounce delay
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement