Hi!
I have a LOL shield (Lots of Led, basically 9x14 Charlieplexed LEDs). You basically light pixels by stating LedSign::Set(x,y,brightness) where brightness can be between 0-7 where 0 is off. LedSign::Clear() clears the board.
On top I have a Nintendo DS Touch Screen and breakout.
I want to create a ripple effect as I tap. I am getting coordinates well but I am having trouble with the programming of the ripple effect. In my coffeescript-version I have it working like below. The first call to the Pulse-function comes with a designated element (which holds x,y).
neighbor = (y,x) ->
pulses++
if (pulses < settings.pulses)
pulse grid[y][x + 1] if x + 1 < xLen
pulse grid[y][x - 1] if x - 1 >= 0
pulse grid[y + 1][x] if y + 1 < yLen
pulse grid[y - 1][x] if y - 1 >= 0
pulse = (el) ->
if !isTouch
unless el.flag
toggle el,settings
el.flag = true
setTimeout (->
neighbor el.y, el.x
setTimeout (->
el.flag = false
),settings.interval
return
),settings.interval
return
I tried basically porting it to Arduino but unsure about the end result. I am not 100% or even 20% sure on how recursiveness behaves on the Arduino.
I have tried setting a 2d array with 0/1 so i can check which led's have been lit. But the actual ripple effect does not come across very well..
Here is my ported code which does not work properly.
void loop() {
/*x1++;
x2--;
y1++;
y2--;
if (grid[x][y] == 0) {
//grid[x][y] = 1;
LedSign::Set(x,y,1%SHADES);
LedSign::Set(x1,y1,1%SHADES);
LedSign::Set(x1,y2,1%SHADES);
LedSign::Set(x2,y1,1%SHADES);
LedSign::Set(x2,y2,1%SHADES);
}*/
if (!flag) {
pulse(x,y);
flag = true;
}
}
void pulse(int x,int y) {
//if (grid[x][y] == 0) {
//grid[x][y] = 1;
LedSign::Set(x,y,1%SHADES);
delay(50);
neighbor(x,y);
//}
}
void neighbor(int x,int y) {
a++;
if (a < 80) {
//LedSign::Set(x,y+1,1);
//LedSign::Set(x,y-1,1);
//LedSign::Set(x+1,y,1);
//LedSign::Set(x-1,y,1);
pulse(x,y+1);
pulse(x,y-1);
pulse(x+1,y);
pulse(x-1,y);
}
}
Would love some feedback on this.
Thanks.