I’ve got another question to ask of the community. I’ve managed to create a few patterns using my neopixel ring. I want to be able to have the ring switch between different patterns. How would I go about doing this?
int mode = 0;
void setup(){
//setup your leds here and other stuff
}
void loop(){
switch(mode){
case 1: your_first_pattern(); break;
case 2: your_second_pattern(); break;
}
FastLED.show();
}
void your_first_pattern(){
//insert code here
}
void your_second_pattern(){
//insert code here
}
Expanding on what Jon said, if you have other things going on, such as getting information from say an RF signal, you’re better off using the loop() just for that, have it go as fast as it can, and pull the switch case outside of it. I posted an example here: http://pastebin.com/2XvRCdDL
This makes debugging also easier. You can simply comment out the ‘displayPattern()’ call from within loop() and focus on just the processing of whatever trigger you’re using, be it RF data, or a button, or Wire … Once you have that sorted out, you can uncomment displayPattern() and let it run again.
I personally keep them in separate files as well. I have one file that’s running code (ino or cpp), and another file (header) that has all the patterns code. This allows me to quickly and easily include the patterns into whatever project I’m working on that needs some funk added. Just include the header file and call the pattern.
@Ashley_M_Kirchner_No I looked into your code and saw uint8_t and uint32_t pop up several times. What excatly is the difference between int and uint8_t?
C++ --> Arduino
uint8_t == byte
uint16_t == unsigned int
uint32_t == unsigned long
… and the reason I do that is because the Arduino INT is in reality an int16_t and it will allocate that amount of memory space for it as well. However, if all I’m working with are values between 0-255, why waste the memory? int8_t is 0-255 only. So I would rather stick with platform INdependent data types and save on memory usage.