NewLinuxFan
Well-known member
My sketch works for a period of time, then stops working. The amount of time that it works depends on how quickly I repeatedly press keys on the keyboard (musical) and also the number of LED's enabled in the code. At 11 or 12 lights it works with infrequent key pressing but stops working when I press the keys rapidly. 1 light, 8 lights, and 10 lights seem to work indefinitely, even with rapid pressing of keys.
Originally, I was working on multi-tab code that is longer than anybody here wants to read, but now I've been trying this shorter code for debugging. There's no millis() used, and the problem still happens.
It's not the polyfuse because the LED's are powered by a different power supply, and if I comment out this line near the bottom:
the indicator LED will remain on even after the Neopixels stop responding to MIDI input. And with my original sketch, I noticed the same problem without any Neopixels connected, just watching an indicator LED that stopped turning on.
Maybe it could be a RAM issue, but when it compiles it says global variables only use 30% of dynamic memory, 2472 out of 8192 bytes. It's hard to imagine that the MIDI library and 12 Neopixels and a simple sketch could max out the RAM.
The same problem happens with the Neopixel library, but the strand test example works fine without issues. Colorpalette test example works fine with FastLED library.
The problem also happens if I don't use callbacks and use the MIDI library the other way.
Any ideas about what's going on?
Originally, I was working on multi-tab code that is longer than anybody here wants to read, but now I've been trying this shorter code for debugging. There's no millis() used, and the problem still happens.
Code:
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
#include <FastLED.h>
#define NUM_LEDS 12
#define DATA_PIN 17
CRGB leds[NUM_LEDS];
unsigned int Fadeoff;
void handleNoteOn(byte channel, byte pitch, byte velocity)
{
Fadeoff = 4095;
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i].setRGB(Fadeoff >> 4, Fadeoff >> 6, 0);
}
FastLED.show();
digitalWriteFast(13, HIGH);
}
void setup()
{
MIDI.begin(MIDI_CHANNEL_OMNI);
MIDI.setHandleNoteOn(handleNoteOn);
pinMode(13, OUTPUT); // Indicator LED on Teensy LC.
FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
digitalWriteFast(13, LOW);
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB::Black;
}
FastLED.show();
}
void loop()
{
while (1)
{
MIDI.read();
if (Fadeoff)
{ Fadeoff -= ((Fadeoff >> 8) + 2);
if (Fadeoff < 0) {
Fadeoff = 0;
}
}
else {
digitalWriteFast(13, LOW);
};
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i].setRGB(Fadeoff >> 4, Fadeoff >> 6, 0);
}
FastLED.show();
}
}
It's not the polyfuse because the LED's are powered by a different power supply, and if I comment out this line near the bottom:
Code:
digitalWriteFast(13, LOW);
the indicator LED will remain on even after the Neopixels stop responding to MIDI input. And with my original sketch, I noticed the same problem without any Neopixels connected, just watching an indicator LED that stopped turning on.
Maybe it could be a RAM issue, but when it compiles it says global variables only use 30% of dynamic memory, 2472 out of 8192 bytes. It's hard to imagine that the MIDI library and 12 Neopixels and a simple sketch could max out the RAM.
The same problem happens with the Neopixel library, but the strand test example works fine without issues. Colorpalette test example works fine with FastLED library.
The problem also happens if I don't use callbacks and use the MIDI library the other way.
Any ideas about what's going on?