Hi im a newbie trying arduino coding, I wanted the ws2812 to be controlled by button, so if the button is pressed the ws2812 will turn on once for 3 seconds then turn off.
Thanks for your suggestions
bokthestudent:
Hi im a newbie trying arduino coding, I wanted the ws2812 to be controlled by button, so if the button is pressed the ws2812 will turn on once for 3 seconds then turn off.
Thanks for your suggestions
First things first, post your code so people can take a look at it and see what you're doing or not doing.
currTime = millis();
if (buttonState == HIGH ){
ledState = ON;
remTime=currentTime;
}
if (currTime - remTime >= 3000 && ledState == ON ) {
#define BRIGHTNESS 180
FastLED.setBrightness(BRIGHTNESS);
fill_solid(leds[0], NUM_LEDS_PER_STRIP, CRGB::Red);
FastLED.show();
}
Although it seems like a simple problem, what if the button is pressed while the LED is On? Do you want to ignore it, turn the LED off, or restart the 3 second timer? The answer to the latter question will greatly affect how this is coded.
In the meant time, here are a couple of tutorials to look at. I would start with just getting the LED to turn on for 3 seconds then add the button:
bokthestudent:
currTime = millis();
if (buttonState == HIGH ){
ledState = ON;
remTime=currentTime;
}
if (currTime - remTime >= 3000 && ledState == ON ) {
ledState = ON;
#define BRIGHTNESS 180
FastLED.setBrightness(BRIGHTNESS);
fill_solid(leds[0], NUM_LEDS_PER_STRIP, CRGB::Red);
FastLED.show();
}
That is not a complete sketch.
bokthestudent:
currTime = millis();if (buttonState == HIGH ){
ledState = ON;
remTime=currentTime;
}if (currTime - remTime >= 3000 && ledState == ON ) {
remTime = currTime;
ledState = ON;
#define BRIGHTNESS 180
FastLED.setBrightness(BRIGHTNESS);
fill_solid(leds[0], NUM_LEDS_PER_STRIP, CRGB::Red);
FastLED.show();
}
Which is only a snippet of your code. You'll need to post your ENTIRE sketch.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.