Hi all,
I'm trying to make the NeoPixel button cycler from Tweaking4all run on a Seed Xiao.
I've already replaced the bits of code to record the current program selected, the problem is the part of the code to reset the loop and make the strip start with the new pattern.
Originally:
void changeEffect() {
if (digitalRead (BUTTON) == HIGH) {
selectedEffect++;
EEPROM.put(0, selectedEffect);
asm volatile (" jmp 0");
}
}
The problem is the asm volatile (" jmp 0");
I replaced it for NVIC_SystemReset :
void changeEffect() {
if (digitalRead (BUTTON) == HIGH) {
selectedEffect++;
storedeffect.write(selectedEffect);
NVIC_SystemReset();
}
}
The problem is, it seems to reset the seed without updating the count.
So you are stuck on the first case.
I've read somewhere to use it like
NVIC_SystemReset(void)
But I get "expected primary-expression before 'void'.
Also tried the
void(* resetFunc) (void) = 0;//declare reset function at address 0
...
resetFunc(); //call reset
When the button is pressed it stops the code. It might got stuck con the void(* resetFunc)...
This is the code before the LED patterns :
(Source : Tweaking4All.com - Arduino – All LEDStrip effects in one (NeoPixel and FastLED))
#include <FlashAsEEPROM.h>
#include <FlashStorage.h>
#include <Adafruit_NeoPixel.h>
#define NUM_LEDS 22
#define PIN 10
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
#define BUTTON 9
byte selectedEffect=0;
FlashStorage(storedeffect, int);
void setup()
{
strip.begin();
strip.show(); // Initialize all pixels to 'off'
pinMode(2,INPUT_PULLUP); // internal pull-up resistor
attachInterrupt (digitalPinToInterrupt (BUTTON), changeEffect, CHANGE); // pressed
}
// *** REPLACE FROM HERE ***
void loop() {
int selectedEffect = storedeffect.read();
if(selectedEffect>18) {
selectedEffect=0;
storedeffect.write(selectedEffect);
}
switch(selectedEffect) {
case 0 : {
// RGBLoop - no parameters
RGBLoop();
break;
}
case 1 : {
// FadeInOut - Color (red, green. blue)
FadeInOut(0xff, 0x00, 0x00); // red
FadeInOut(0xff, 0xff, 0xff); // white
FadeInOut(0x00, 0x00, 0xff); // blue
break;
}
case 2 : {
// Strobe - Color (red, green, blue), number of flashes, flash speed, end pause
Strobe(0xff, 0xff, 0xff, 10, 50, 1000);
break;
}
case 3 : {
// HalloweenEyes - Color (red, green, blue), Size of eye, space between eyes, fade (true/false), steps, fade delay, end pause
HalloweenEyes(0xff, 0x00, 0x00,
1, 4,
true, random(5,50), random(50,150),
random(1000, 10000));
HalloweenEyes(0xff, 0x00, 0x00,
1, 4,
true, random(5,50), random(50,150),
random(1000, 10000));
break;
}
case 4 : {
// CylonBounce - Color (red, green, blue), eye size, speed delay, end pause
CylonBounce(0xff, 0x00, 0x00, 4, 10, 50);
break;
}
case 5 : {
// NewKITT - Color (red, green, blue), eye size, speed delay, end pause
NewKITT(0xff, 0x00, 0x00, 8, 10, 50);
break;
}
case 6 : {
// Twinkle - Color (red, green, blue), count, speed delay, only one twinkle (true/false)
Twinkle(0xff, 0x00, 0x00, 10, 100, false);
break;
}
case 7 : {
// TwinkleRandom - twinkle count, speed delay, only one (true/false)
TwinkleRandom(20, 100, false);
break;
}
case 8 : {
// Sparkle - Color (red, green, blue), speed delay
Sparkle(0xff, 0xff, 0xff, 0);
break;
}
case 9 : {
// SnowSparkle - Color (red, green, blue), sparkle delay, speed delay
SnowSparkle(0x10, 0x10, 0x10, 20, random(100,1000));
break;
}
case 10 : {
// Running Lights - Color (red, green, blue), wave dealy
RunningLights(0xff,0x00,0x00, 50); // red
RunningLights(0xff,0xff,0xff, 50); // white
RunningLights(0x00,0x00,0xff, 50); // blue
break;
}
case 11 : {
// colorWipe - Color (red, green, blue), speed delay
colorWipe(0x00,0xff,0x00, 50);
colorWipe(0x00,0x00,0x00, 50);
break;
}
case 12 : {
// rainbowCycle - speed delay
rainbowCycle(20);
break;
}
case 13 : {
// theatherChase - Color (red, green, blue), speed delay
theaterChase(0xff,0,0,50);
break;
}
case 14 : {
// theaterChaseRainbow - Speed delay
theaterChaseRainbow(50);
break;
}
case 15 : {
// Fire - Cooling rate, Sparking rate, speed delay
Fire(55,120,15);
break;
}
// simple bouncingBalls not included, since BouncingColoredBalls can perform this as well as shown below
// BouncingColoredBalls - Number of balls, color (red, green, blue) array, continuous
// CAUTION: If set to continuous then this effect will never stop!!!
case 16 : {
// mimic BouncingBalls
byte onecolor[1][3] = { {0xff, 0x00, 0x00} };
BouncingColoredBalls(1, onecolor, false);
break;
}
case 17 : {
// multiple colored balls
byte colors[3][3] = { {0xff, 0x00, 0x00},
{0xff, 0xff, 0xff},
{0x00, 0x00, 0xff} };
BouncingColoredBalls(3, colors, false);
break;
}
case 18 : {
// meteorRain - Color (red, green, blue), meteor size, trail decay, random trail decay (true/false), speed delay
meteorRain(0xff,0xff,0xff,10, 64, true, 30);
break;
}
}
}
void changeEffect() {
if (digitalRead (BUTTON) == HIGH) {
selectedEffect++;
storedeffect.write(selectedEffect);
NVIC_SystemReset();
}
}
Many thanks