Hallo zusammen,
ich habe mir folgenden RunningLED Code gebastelt, der in beide Richtungen einstellbar ist.
Bei Direction = FORWARD funktioniert es erstmal wie gewünscht, bei Direction = REVERSE, gibt es, wenn Increment wieder zurückgesetzt wird, einen deutlich sichtbaren Ruckler.
Ich kann mir den nicht erklären.
#include <Adafruit_NeoPixel.h>
enum EffectDirection { FORWARD, REVERSE };
const uint8_t LEDPIN1 = 5;
const uint16_t NUMPIXELS1 = 300;
Adafruit_NeoPixel strip1(NUMPIXELS1, LEDPIN1, NEO_GRB + NEO_KHZ800);
int Increment = 0;
int StartLED = 1;
int EndLED = 40;
uint32_t Color1 = 0x0000DD;
int Direction = FORWARD;
void setup() {
strip1.begin();
strip1.clear();
strip1.show();
}
void loop() {
int ml = (EndLED - StartLED);
if (Increment >= ml) { Increment = 0; }
Increment++;
if (Direction == REVERSE) {
for (uint16_t i = StartLED; i <= EndLED; i++) {
strip1.setPixelColor(i, ((sin(Increment + i) * 127 + 128) / 255) * ((Color1 >> 16) & 0xFF),
((sin(Increment + i) * 127 + 128) / 255) * ((Color1 >> 8) & 0xFF),
((sin(Increment + i) * 127 + 128) / 255) * (Color1 & 0xFF));
}
}
else { // Forward
for (uint16_t i = StartLED; i <= EndLED; i++) {
strip1.setPixelColor(i, ((sin(i - Increment) * 127 + 128) / 255) * ((Color1 >> 16) & 0xFF),
((sin(i - Increment) * 127 + 128) / 255) * ((Color1 >> 8) & 0xFF),
((sin(i - Increment) * 127 + 128) / 255) * (Color1 & 0xFF));
}
}
strip1.show();
delay(50);
}
ec2021
August 17, 2023, 9:41pm
2
Moin @liebelein01 ,
leider lässt sich der Effekt bei Wokwi nicht nachstellen (zumindest erkenne ich ihn dort leider nicht):
/*
Forum: https://forum.arduino.cc/t/mit-unerklarlicher-ruckler-bei-led-effekt/1159262
Wokwi: https://wokwi.com/projects/373344458406571009
*/
#include <Adafruit_NeoPixel.h>
enum EffectDirection { FORWARD, REVERSE };
const uint8_t LEDPIN1 = 5;
const uint16_t NUMPIXELS1 = 300;
Adafruit_NeoPixel strip1(NUMPIXELS1, LEDPIN1, NEO_GRB + NEO_KHZ800);
constexpr byte ledRed = 7;
int Increment = 0;
int StartLED = 1;
int EndLED = 40;
uint32_t Color1 = 0x0000DD;
int Direction = FORWARD;
void setup() {
Serial.begin(115200);
strip1.begin();
strip1.clear();
strip1.show();
pinMode(ledRed,OUTPUT);
}
int count = 0;
void loop() {
int ml = (EndLED - StartLED);
if (Increment >= ml) {
Increment = 0;
digitalWrite(ledRed,HIGH);
count++;
}
if (Increment == 10) {digitalWrite(ledRed,LOW);}
Increment++;
if (Direction == REVERSE) {
for (uint16_t i = StartLED; i <= EndLED; i++) {
strip1.setPixelColor(i, ((sin(Increment + i) * 127 + 128) / 255) * ((Color1 >> 16) & 0xFF),
((sin(Increment + i) * 127 + 128) / 255) * ((Color1 >> 8) & 0xFF),
((sin(Increment + i) * 127 + 128) / 255) * (Color1 & 0xFF));
}
}
else { // Forward
for (uint16_t i = StartLED; i <= EndLED; i++) {
strip1.setPixelColor(i, ((sin(i - Increment) * 127 + 128) / 255) * ((Color1 >> 16) & 0xFF),
((sin(i - Increment) * 127 + 128) / 255) * ((Color1 >> 8) & 0xFF),
((sin(i - Increment) * 127 + 128) / 255) * (Color1 & 0xFF));
}
}
strip1.show();
delay(50);
if (count >= 2){
count = 0;
Increment = 0;
if (Direction == REVERSE) {
Direction = FORWARD;
Serial.println("FORWARD");
} else {
Direction = REVERSE;
Serial.println("REVERSE");
}
}
}
Siehe hier: https://wokwi.com/projects/373344458406571009
Habe versucht speziell dann, wenn die hinzugefügte Led aufleuchtet, etwas zu sehen, aber ohne Erfolg. Vielleicht kannst Du mit den Debug-Ansätzen etwas anfangen ...
Viel Erfolg!
Sin benutzt als Eingang das Bogenmass. also 2PI r. Du benutzt Ganzzahlen. Ich habe es jetzt nicht durchgerechnet, vermute hier aber die Ursache.
1 Like
Hallo,
schau Dir mal die Lib FastLED an , da gibt es eine 8 bit Berechnung die sehr schnell ist und extra für sowas gemacht ist.
Vielen Dank für Eure Ansätze, ich werde mich mit allen Beschäftigen und Berichten ob und wie ich es lösen konnte.
Gruß
agmue
August 18, 2023, 2:20pm
7
Mir hilft häufig der serielle Monitor (getestet mit UNO):
for (uint16_t i = StartLED; i <= EndLED; i++) {
strip1.setPixelColor(i, ((sin(Increment + i) * 127 + 128) / 255) * ((Color1 >> 16) & 0xFF),
((sin(Increment + i) * 127 + 128) / 255) * ((Color1 >> 8) & 0xFF),
((sin(Increment + i) * 127 + 128) / 255) * (Color1 & 0xFF));
Serial.print( i );
Serial.print('\t');
Serial.print( Increment );
Serial.print('\t');
Serial.print( i + Increment );
Serial.print('\t');
Serial.print( i - Increment );
Serial.print('\t');
Serial.print( (sin(Increment + i) * 127 + 128) / 255 );
Serial.print('\t');
Serial.print( ((Color1 >> 16) & 0xFF) );
Serial.print('\t');
Serial.print( ((Color1 >> 8) & 0xFF) );
Serial.print('\t');
Serial.println( (Color1 & 0xFF) );
}
Die problematische Stelle habe ich rot markiert:
i
Inc
i + Inc
i - Inc
sin
28
39
67
65525
0.08
0
0
221
29
39
68
65526
0.05
0
0
221
30
39
69
65527
0.44
0
0
221
31
39
70
65528
0.89
0
0
221
32
39
71
65529
0.98
0
0
221
33
39
72
65530
0.63
0
0
221
34
39
73
65531
0.16
0
0
221
35
39
74
65532
0.01
0
0
221
36
39
75
65533
0.31
0
0
221
37
39
76
65534
0.78
0
0
221
38
39
77
65535
1.00
0
0
221
39
39
78
0
0.76
0
0
221
40
39
79
1
0.28
0
0
221
1
1
2
0
0.95
0
0
221
2
1
3
1
0.57
0
0
221
3
1
4
2
0.13
0
0
221
4
1
5
3
0.02
0
0
221
5
1
6
4
0.36
0
0
221
6
1
7
5
0.83
0
0
221
7
1
8
6
0.99
0
0
221
8
1
9
7
0.71
0
0
221
9
1
10
8
0.23
0
0
221
Ich bekomme auch noch Warnungen:
warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (uint16_t i = StartLED; i <= EndLED; i++) {
~~^~~~~~~~~
system
Closed
February 14, 2024, 2:20pm
8
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.