Skip to content

Commit

Permalink
UserModLive: artifx effects testing (WIP)
Browse files Browse the repository at this point in the history
Added beatMania and Green Ripple Reflections

pio.ini move to asmParser 2.1.1

LedEffects: add slider2

UserModLive:
- add triangle, time, beatSin8, fadeToBlackBy, sCFP (Set color from pixel)
  • Loading branch information
ewoudwijma committed Aug 8, 2024
1 parent 39736a5 commit 5a4778c
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 4 deletions.
55 changes: 55 additions & 0 deletions misc/beatmaniaSL.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//from https://github.com/MoonModules/WLED-Effects/blob/master/ARTIFX/wled/beatmania.wled
//Created by Andrew Tuline Converted by Ewoud Wijma

uint8_t locn1;
uint8_t locn2;
uint8_t locn3;
uint8_t locn12;

uint8_t colr1;
uint8_t colr2;
uint8_t colr3;
uint8_t colr12;

uint8_t bri1;
uint8_t bri2;
uint8_t bri3;
uint8_t bri12;

void setup()
{
}


void loop() {

//fadeToBlackBy(slider2/8); // Adjustable fade rate.

locn1 = beatSin8(slider1/3+1,0,width) ; // Adjustable speed.
locn2 = beatSin8(slider1/4+1,0,width);
locn3 = beatSin8(slider1/5+1,0,width/2+width/3);

colr1 = beatSin8(slider2/6+1,0,255);
colr2 = beatSin8(slider2/7+1,0,255);
colr3 = beatSin8(slider2/8+1,0,255);

bri1 = beatSin8(slider2/6+1,32,255);
bri2 = beatSin8(slider2/7+1,32,255);
bri3 = beatSin8(slider2/8+1,32,255) ; // One too many beats.

locn12 = locn1+locn2;
colr12 = colr1+colr2;
bri12 = bri1+bri2;
sCFP(locn12,colr12,bri12);
sCFP(locn1,colr2,bri1);
sCFP(locn2%(width-1),colr1,bri2);
}

void main() {
resetStat();
setup();
while (2>1) {
loop();
show();
}
}
54 changes: 54 additions & 0 deletions misc/green_ripple_reflectionsSL.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//https://github.com/MoonModules/WLED-Effects/blob/master/ARTIFX/wled/green_ripple_reflections.wled
//original from https://patterns.electromage.com/pattern/Ktjben4j36Wqxnk8N
//Converted by Andrew Tuline and Ewoud Wijma

float PI2;
float PI6;
float PI10;

float t1;
float t2;
float t3;

float a;
float b;
float c;
float v;

void setup()
{
PI2 = 6.28318;
PI6 = PI2 * 3;
PI10 = PI2 * 5;
}


void loop() {

t1 = time(0.03) * PI2;
t2 = time(0.05) * PI2;
t3 = time(0.04) * PI2;

for (uint8_t index = 0; index < width; index++) {
a = sin(index * PI10 / width + t1);
a = a * a;
b = sin(index * PI6 / width - t2);
c = triangle(index * 3 / width + 1 + sin(t3) / 2 % 1);
v = (a + b + c) / 3;
v = v * v;
//printCustom((float)index,a,b,c,v);
CRGB gg = hsv(0.3 * 255, a * 255, v * 255);
for (uint8_t y = 0; y < height; y++) {
sPC(0, y*panel_width+index, gg);
}
}
}

void main() {
resetStat();
setup();
while (2>1) {
loop();
show();
}
}
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ build_flags =
-D STARBASE_USERMOD_LIVE
lib_deps =
; https://github.com/hpwit/ASMParser.git#4b2da1a ; mem branche commit of 20240716
https://github.com/hpwit/ASMParser.git#v2 ;
https://github.com/hpwit/ASMParser.git#v2.1.1 ;

[STARLIGHT_CLOCKLESS_LED_DRIVER]
build_flags =
Expand Down
1 change: 1 addition & 0 deletions src/App/LedEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -2983,6 +2983,7 @@ class LiveScriptEffect: public Effect {
}}); //script

ui->initSlider(parentVar, "Slider1", &slider1);
ui->initSlider(parentVar, "Slider2", &slider2);

}
};
Expand Down
29 changes: 26 additions & 3 deletions src/User/UserModLive.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,41 @@ static void resetShowStats()
static void dispshit(int g) { ppf("coming from assembly int %x %d", g, g);}
static void __print(char *s) {ppf("from assembly :%s\r\n", s);}
static void showError(int line, uint32_t size, uint32_t got) { ppf("Overflow error line %d max size: %d got %d", line, size, got);}
static void displayfloat(float j) {ppf("display float %f", j);}
static void displayfloat(float j) {ppf(" %f", j);}

static float _hypot(float x,float y) {return hypot(x,y);}
static float _atan2(float x,float y) { return atan2(x,y);}
static float _sin(float j) {return sin(j);}
static float _triangle(float j) {return 1.0 - fabs(fmod(2 * j, 2.0) - 1.0);}
static float _time(float j) {
float myVal = sys->now();
myVal = myVal / 65535 / j; // PixelBlaze uses 1000/65535 = .015259.
myVal = fmod(myVal, 1.0); // ewowi: with 0.015 as input, you get fmod(millis/1000,1.0), which has a period of 1 second, sounds right
return myVal;
}

//LEDS specific
static CRGB POSV(uint8_t h, uint8_t s, uint8_t v) {return CHSV(h, s, v);}
static CRGB POSV(uint8_t h, uint8_t s, uint8_t v) {return CHSV(h, s, v);} //why call POSV and not hsv?
static uint8_t _sin8(uint8_t a) {return sin8(a);}
static float _beatSin8(uint8_t a1, uint8_t a2, uint8_t a3) {return beatsin8(a1, a2, a3);}
static LedsLayer *gLeds = nullptr;
static void _fadeToBlackBy(uint8_t a1) {gLeds->fadeToBlackBy(a1);}
static void sPCLive(int t, uint16_t pixel, CRGB color) { // int t needed - otherwise wrong colors, very strange
if (gLeds)
{
// if (t == 0) ppf(" %d,%d,%d", color.r, color.g, color.b);
gLeds->setPixelColor(pixel, color);
}
}
uint8_t slider1 = 10;
static void sCFPLive(uint16_t pixel, uint8_t index, uint8_t brightness) { // int t needed - otherwise wrong colors, very strange
if (gLeds)
{
// if (t == 0) ppf(" %d,%d,%d", color.r, color.g, color.b);
gLeds->setPixelColor(pixel, ColorFromPalette(gLeds->palette, index, brightness));
}
}
uint8_t slider1 = 128;
uint8_t slider2 = 128;

//End LEDS specific

Expand Down Expand Up @@ -160,6 +177,9 @@ class UserModLive:public SysModule {
addExternalFun("float", "atan2","(float a1, float a2)",(void*)_atan2);
addExternalFun("float", "hypot","(float a1, float a2)",(void*)_hypot);
addExternalFun("float", "sin", "(float a1)", (void *)_sin);
addExternalFun("float", "time", "(float a1)", (void *)_time);
addExternalFun("float", "triangle", "(float a1)", (void *)_triangle);
addExternalFun("uint8_t", "beatSin8", "(uint8_t a1, uint8_t a2, uint8_t a3)", (void *)_beatSin8);

// added by StarBase
addExternalFun("void", "pinMode", "(int a1, int a2)", (void *)&pinMode);
Expand All @@ -173,10 +193,13 @@ class UserModLive:public SysModule {
addExternalFun("CRGB", "hsv", "(int a1, int a2, int a3)", (void *)POSV);
addExternalFun("uint8_t", "sin8","(uint8_t a1)",(void*)_sin8); //using int here causes value must be between 0 and 16 error!!!
addExternalFun("void", "sPC", "(int a0, int a1, CRGB a2)", (void *)sPCLive); // int t needed - otherwise wrong colors, very strange
addExternalFun("void", "sCFP", "(uint16_t pixel, uint8_t index, uint8_t brightness)", (void *)sCFPLive);
addExternalFun("void", "fadeToBlackBy", "(uint8_t a1)", (void *)_fadeToBlackBy);
//address of overloaded function with no contextual type information: setPixelColorLive
//ISO C++ forbids taking the address of a bound member function to form a pointer to member function. Say '&LedsLayer::setPixelColorLive' [-fpermissive]
//converting from 'void (LedsLayer::*)(uint16_t, uint32_t)' {aka 'void (LedsLayer::*)(short unsigned int, unsigned int)'} to 'void*' [-Wpmf-conversions]
addExternalVal("uint8_t", "slider1", &slider1); //used in map function
addExternalVal("uint8_t", "slider2", &slider2); //used in map function

//End LEDS specific

Expand Down

0 comments on commit 5a4778c

Please sign in to comment.