Need your help with really strange Spark behavior.
So I’ve been porting over some of the visualizations for my L3D Cube from Arduino to the Spark and I’ve found a some really strange behavior that I can’t explain. The specific viz takes the twinkle that @kriegsman created and add’s support for the built-in mic to make it reactive to sound. I have it working well. You can see the original code here: Twinkle mic working - Pastebin.com and the viz here: - YouTube.
Here’s where it gets weird. I was making some seemingly innocent modifications to the code and I got very different behaviors.
#1 - If you change line 93 to mic /=4; you get this: - YouTube. There are no twinkles and it is mildly reactive to sound and I’ve lost the palette.
#2 - If you add a third call to dim8_raw after line 95, you get this: - YouTube. Twinkles and reactive but no palette.
#3 - If you take the code from line 92 to line 110 and move it to a separate function, you get this: - YouTube. You lose the smooth dimming.
Here’s another case of Spark strangeness. I start with Mark’s standard twinkle here: - YouTube, and I try to add in a rotating palette. So I’ve simplified the problem to just making a call to millis() in the loop and I get this: - YouTube. The same kind of jerky behavior as #3 above.
Anyone have any ideas?
Huh. That last one makes me start thinking. I haven’t finished thinking yet, but that one is interesting. And that’s just from adding a call to millis() ?
yup. The really strange thing is that the sketch has exactly similar code to the working mic sample that does the rotating palette with millis() but I can’t get it to compile and resolve the FastLED built-in palettes. Here’s the code: http://pastebin.com/zDnG17Td.
Just curious: set MASTER_BRIGHTNESS to 255. Any difference? How about 32?
Which version do you want me to try it on?
The one that would have been “#4”?
It was 255 and wonky. Setting it to 32 is just as bad.
If I just comment out the mic inputs from the loop and increase the density to 255, I get the twinkle with palette support, no wonky. The difference between working and not working is a knife edge. So strange.
Also as diagnostic, try checking FastLED.getFPS() in the smooth vs the non-smooth cases?
No place to see the output unless I code it into the leds somehow.
So if you really want to twist your brain, I started diffing the code that that didn’t compile to the one that did and started moving the non-working one toward the working one since it was mostly placement of the code and not a logical difference. Here is the diff:
https://www.diffchecker.com/fujdxbsp. The one on the right compiles and the one on the left gives the following:
twinkle.o: In function beat88': /spark/compile_service/shared/workspace/3_compile-server2/core-firmware/build/FastLED/lib8tion.h:1893: undefined reference toNSFastLED::get_millisecond_timer()’
collect2: error: ld returned 1 exit status
make: * [950147282ddcbec5a4340d26dcec74a91353017d2ee6f5044ece43c80918.elf] Error 1
Ok. So, um. Put an extra CRLF at the end of the file??? #voodoo
And yet more strangeness…
I took the working twinkle and removed the hard-coded palette value from line 125 and went from working to non-working. WTF?
Here’s a diff:
https://www.diffchecker.com/cng4blqf
And here’s the video. The first 5 seconds are the working sketch and the end of the video is the now broken sketch:
So at least one other person is mentioning the CRLF at the end; I’d add that first and then see where we are. 
No change:
Diff says they are identical:
https://www.diffchecker.com/0xemtgms
Same compile error:
twinkle.o: In function beat88': /spark/compile_service/shared/workspace/2_compile-server2/core-firmware/build/FastLED/lib8tion.h:1893: undefined reference toNSFastLED::get_millisecond_timer()’
collect2: error: ld returned 1 exit status
make: * [fd64026b6e7ef11afda8788dca3ea224cf4ae4861f02926d6d1809e4d3bd.elf] Error 1
In the strangest twist of all, I created another app, added the library and then copied the code from the non-compiling sketch and pasted it into a new sketch. The old one still doesn’t compile but the new one does. WTF!?