Hi, everyone.
I'm still in the early stages of learning to program. However, I am slowly despairing of myself and am asking you for advice.
how do I make the led not react to the specified value but slowly (500ms) dim up? i have an rgb ws2812 adafruit on the arduino uno r3...
this is the current programming
int switchState = 0; //zwischenspeicher schalter
#include <Adafruit_NeoPixel.h>
#define PIN 6 // led daten anschluss
#define NUMPIXELS 12 // anzahl led pixels
Adafruit_NeoPixel pixels = Adafruit_NeoPixel (NUMPIXELS , PIN , NEO_GRB + NEO_KHZ800);
void setup() {
pinMode (2,INPUT); // schalter eingang
pixels.begin(); //initialisierung led
pixels.show(); //ausschalten aller leds
}
void loop() { // 0-255 rot,,grün,,blau
switchState = digitalRead (2);
if (switchState == LOW){ // der schalter ist aus
pixels.setPixelColor(1,pixels.Color(0,0,0));
pixels.show();
}
else{
pixels.setPixelColor(1,pixels.Color(0,0,255));
pixels.show();
delay(4000);
}}
I've never used NeoPixels or the library, but...
You have to "step it up". Each color has a brightness level between zero and 256 so you can count-up from zero a little slower than 2ms per step (although you may not want it to be linear (1) ).
The Fade Example may help to explain but it won't work as-is with NeoPixels.
With only 12 NeoPixels you may be OK using delay() or delayMicros() but it takes time to write the NeoPixels so a millis() timer (like the Blink Without Delay Example ) may work better than a regular delay().
(1) A linear fade doesn't look linear because 10-count from 10-to-20 is a bigger percentage change than 245-to-255. In fact you probably won't notice the difference between 245 & 255. But with a fast 500ms fade that shouldn't be an issue.
1 Like
kolaha
April 11, 2022, 9:05pm
3
#include <Adafruit_NeoPixel.h>
#define PIN 6 // led daten anschluss
#define NUMPIXELS 12 // anzahl led pixels
Adafruit_NeoPixel pixels = Adafruit_NeoPixel (NUMPIXELS , PIN , NEO_GRB + NEO_KHZ800);
void setup() {
pinMode (2, INPUT_PULLUP); // schalter eingang
pixels.begin(); //initialisierung led
pixels.show(); //ausschalten aller leds
}
void loop() { // 0-255 rot,,grün,,blau
if (digitalRead (2) == LOW) { // der schalter ist aus
for (byte i = 250; i > 0; i -= 5) {
pixels.setPixelColor(1, pixels.Color(0, 0, i));
pixels.show();
delay(2);
}
}
else {
pixels.setPixelColor(1, pixels.Color(0, 0, 255));
pixels.show();
delay(4000);
}
}
1 Like
Hello kolaha
thanks for the reply... with the attached program, the led flickers until i press the switch. what am I doing wrong?
kolaha
April 13, 2022, 7:52am
5
describe what behavior of system do you expecting.
example:
LED are off
I press and release the button
LED are slowly lights up to maximum in time of 500ms
I press and release the button
LED goes off immediately
go to start
How is your button wired? Between Vcc and pin 2 or between GND and pin 2?
the switch is pressed, the led dims up (500ms) and goes out after 4000ms
then start again...
at the moment it always flickers until it is pressed. switches on without dimming and goes off after (4000).
kolaha
April 13, 2022, 10:07pm
9
#include <Adafruit_NeoPixel.h>
#define PIN 6 // led daten anschluss
#define NUMPIXELS 12 // anzahl led pixels
Adafruit_NeoPixel pixels(NUMPIXELS , PIN , NEO_GRB + NEO_KHZ800);
void setup() {
pinMode (2, INPUT_PULLUP); // schalter eingang
pixels.begin(); //initialisierung led
pixels.show(); //ausschalten aller leds
}
void loop() { // 0-255 rot,,grün,,blau
if (digitalRead (2) == HIGH) { // der schalter ist aus
for (byte i = 0; i <250; i += 5) {
pixels.setPixelColor(1, pixels.Color(0, 0, i));
pixels.show();
delay(2);
}
delay(4000);
pixels.clear();
pixels.show();
}
}
1 Like
Thank you very much...
It goes perfekt.
system
Closed
October 11, 2022, 4:53pm
11
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.