Hey Leute,
ich Zweifel gerade an meinen analytischen Fähigkeiten.
In meinem Sketch gibt es eine Variable: mischeFarbmusterLeds1
Diese wird mit mischeFarbmusterLeds1++ hochgezählt.
Ganz einfach. Die Variable springt aber andauernd. von 255 auf 86, oder irgendwelchen anderen Zahlen.
Am RAM liegt es nicht. ich habe 600Byte frei.
Ich hab dann meinen Nano beiseite gelegt und nen Uno genommen und dort den Sketch nackt ohne Peripherie angeschlossen.
Selbst er verrechnet sich.
Könnt Ihr den sketch bei euch mal laufen lassen und gucken ob auf der Seriellen Konsole das gleiche Verhalten zu sehen ist?
beste Grüße
Sketch (gekürzt, nicht lauffähig da sonst zu lang für den Beitrag, Lauffähig im Anhang als ZIP):
#include <FastLED.h>
#define LED_PIN 6
// Information about the LED strip itself
#define NUM_LEDS 100
#define CHIPSET WS2812B
#define COLOR_ORDER GRB
const int coinPin = 8;
const int rotationPin = 10;
int coinState = 0;
int rotationState = 0;
bool coinFlag = true;
bool rotationFlagTrue = false;
bool rotationFlagFalse = false;
bool playableFlag = false;
byte coinTimer = 60;
unsigned int timerCounter = 0;
byte letztesMuster = 0;
bool rotateFlag = false;
#define BRIGHTNESS 255
const byte maxByte = 255;
#define TEMPERATURE Tungsten100W
byte sinus = 0;
byte wechselFarbe = 0;
// LED Arrays
CRGB anzeigeLeds[NUM_LEDS];
CRGB farbmuster1zuBlend[NUM_LEDS];
CRGB farbmuster2zuBlend[NUM_LEDS];
CHSV gHerzschlag[NUM_LEDS];
CRGB clr1;
CRGB clr2;
bool farbmuster1Wechseln = false;
bool farbmuster1WechselnErfolgt = false;
byte gHue2 = 73;
byte gHue3 = 129;
// LED Aktualisierung
byte framesPerSecond = 120;
byte mischeFarbmusterLeds1 = 0;
#define anzahlPattern 14
bool patterns[anzahlPattern][2];
static bool gesetztesPattern = false;
void setupPatternsOrg() {
if (!gesetztesPattern) {
// Wenn kein Pattern gesetzt wurde, eins setzen
patterns[random(0, anzahlPattern)][0] = true;
patterns[random(0, anzahlPattern)][1] = true;
// Keine doppelten
for (int i = 0; i < anzahlPattern; i++) {
while (patterns[i][0] == patterns[i][1]) {
patterns[i][1] = false;
patterns[random(0, anzahlPattern)][1] = true;
}
}
}
}
void changePatterns() {
// Prüfe ob ein Pattern gesetzt wurde
for (byte i = 0; i < anzahlPattern; i++) {
if (patterns[i][0]) {
gesetztesPattern = true;
}
}
if (gesetztesPattern) {
// Wenn Pattern gesetzt wurde, das andere ändern
unsigned int musterWahl = random8(0, anzahlPattern);
for (byte i = 0; i < anzahlPattern; i++) {
if (!farbmuster1WechselnErfolgt) {
if (farbmuster1Wechseln) {
if (musterWahl == i) {
patterns[i][0] = true;
} else {
patterns[i][0] = false;
}
} else {
if (musterWahl == i) {
patterns[i][1] = true;
} else {
patterns[i][1] = false;
}
}
farbmuster1WechselnErfolgt = true;
}
}
}
}
void setzeMuster() {
if (patterns[0][0]) {
rainbow(farbmuster1zuBlend);
}
if (patterns[1][0]) {
rainbowWithGlitter(farbmuster1zuBlend);
}
if (patterns[2][0]) {
confetti(farbmuster1zuBlend);
}
if (patterns[3][0]) {
sinelon(farbmuster1zuBlend);
}
if (patterns[4][0]) {
juggle(farbmuster1zuBlend);
}
if (patterns[5][0]) {
wabern(farbmuster1zuBlend);
}
if (patterns[0][1]) {
rainbow(farbmuster2zuBlend);
}
if (patterns[1][1]) {
rainbowWithGlitter(farbmuster2zuBlend);
}
if (patterns[2][1]) {
confetti(farbmuster2zuBlend);
}
if (patterns[3][1]) {
sinelon(farbmuster2zuBlend);
}
if (patterns[4][1]) {
juggle(farbmuster2zuBlend);
}
if (patterns[5][1]) {
wabern(farbmuster2zuBlend);
}
}
void mischePufferLedsOrg() {
if (mischeFarbmusterLeds1 == 60) {
farbmuster1Wechseln = true;
changePatterns();
} else {
farbmuster1WechselnErfolgt = false;
}
if (mischeFarbmusterLeds1 == 192) {
farbmuster1Wechseln = false;
changePatterns();
} else {
farbmuster1WechselnErfolgt = false;
}
setzeMuster();
}
void mischeAnzeigeLeds() {
mischePufferLedsOrg();
CHSV spectrumcolor;
for (int i = 0; i < NUM_LEDS; i++) { // mix the 2 arrays together
anzeigeLeds[i] = blend( farbmuster1zuBlend[i], farbmuster2zuBlend[i], sin8(mischeFarbmusterLeds1 ));
}
}
void zeigeFarben() {
FastLED.show();
}
void musterRotation() {
//if (rotationFlagFalse && rotationFlagTrue && coinTimer > 0 && rotateFlag) {
if (coinTimer < 20) {
coinTimer += 5;
}
Serial.println(mischeFarbmusterLeds1);
mischeFarbmusterLeds1++;
rotationFlagFalse = false;
rotationFlagTrue = false;
rotateFlag = false;
// }
}
void readButtons() {
// read the state of the buttons:
coinState = digitalRead(coinPin);
rotationState = digitalRead(rotationPin);
if (rotationState == HIGH) {
rotationFlagTrue = true;
} else {
rotationFlagFalse = true;
}
// check if the coin is inserted. If it is, the coinState is HIGH:
if (coinState == HIGH) {
// set flag on:
if (coinTimer < 30) {
coinFlag = true;
coinTimer = 30;
timerCounter = 0;
}
} else {
coinFlag = false;
}
}
void loop()
{
readButtons();
EVERY_N_MILLISECONDS(20)
{
sinus++;
rotateFlag = true;
musterRotation();
}
EVERY_N_MILLISECONDS(1000 / framesPerSecond)
{
if (playableFlag) {
mischeAnzeigeLeds();
} else {
schlafen();
}
gHue++;
FastLED.show();
}
EVERY_N_SECONDS(1)
{
if (coinTimer > 0) {
coinTimer--;
timerCounter++;
playableFlag = true;
} else {
playableFlag = false;
}
//Serial.println(coinTimer);
}
}
void setup() {
delay( 1000 ); // power-up safety delay
Serial.begin(115200);
pinMode(coinPin, INPUT);
pinMode(rotationPin, INPUT);
setupZufall();
setupPuk();
setupPatternsOrg();
}
void setupZufall() {
CreateTrulyRandomSeed();
randomSeed(seed);
}
void setupPuk() {
Serial.println("Start...");
setzeHerzFarbe();
gHerzSaettigung = random(maxByte * 0.7, maxByte);
setzeHerzVariation();
setzeHerzschlagFrequenz(30, 120);
FastLED.setBrightness( BRIGHTNESS );
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(anzeigeLeds, NUM_LEDS).setCorrection( TypicalSMD5050 );
FastLED.setTemperature( TEMPERATURE );
}
Beispielliste:
Start...
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
232
255
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
255
255
226
255
130
164
165
166
167
168
Kaleidoskop.zip (13.3 KB)