Ok, so i just need a little help with integrating the loop from this:
http://pastebin.com/JtLYuPdm
into the code to display the leds in this: (the final code in progress)
http://pastebin.com/LApe9Wis
How would I adapt my code
// Figure out how many leds would be lit, and in what direction
int XLit = abs(AcX) / (25000/(NUM_LEDS/2));
// sanity check, just in case we get larger values than we’re expecting!
if(XLit > (NUM_LEDS/2)) {
XLit = NUM_LEDS/2;
}
// empty out the existing leds
fill_solid(Xleds,NUM_LEDS,CRGB::Black);
if(AcX < 0) {
// we want to light up numLit leds, starting from the midpoint, going down
for(int xi = 1; xi <= XLit; xi++) {
Xleds[(NUM_LEDS/2)-xi] = CRGB::Green;
}
} else {
// we want to light up numLit leds, starting from the midpoint, going forward
for(int xi = 0; xi < XLit; xi++) {
Xleds[(NUM_LEDS/2)+xi] = CRGB::Yellow;
}
}
And merge this into it to use a sine wave to fade in and out the leds rather than having them be on or off?
(only controls the red leds from the three sin demo)
wave1 += inc1;
for (int k=0; k<NUM_LEDS; k++) {
leds[k].r = qsub8(quadwave8(mul1*k + wave1), lvl1);
}
I’m sure it’s possible, I’m just having trouble with putting what integers where so that it works correctly.
Try just getting one direction working first, before trying to program every aspect of it. I can’t really offer too much assistance without having a rig here to test on as well…
That makes sense, thank you!
Just thinking a bit about how I would possibly go about it. So your sensor range is approx 64,000 increments (-32000 - +32000), and you want 15 leds per axis. So that means one LED is center and 7 LEDs for each up and down motion. That means, 64,000 / 7 = ~9142 increments of potential fade for each LED. That’s a bit much so you will want to scale that to a more suitable range for LED usage. Following along?
Yeah that makes sense. I’m not incredibly particular about the brightness of each led directly reflect the values they’re showing, I’m going to be using 7 segment displays to show actual readings from the accelerometer mapped to show exact “G” readings. I want the LEDs to fade in and out mostly because of the way it would look, and I have a feeling it would get distracting if they were going back and forth between full on and off repeatedly, especially at night. Since the final project will be mounted in a turbocharged 450+ horsepower sports car. Lol
If I’m reading the code correct, “k” is the “location” of the sine wave. If we somehow replace “k” with a mapped value of AcX the sine waves would move with the sensor readings. Is that correct?
wave1 += inc1;
for (int k=0; k<NUM_LEDS; k++) {
leds[k].r = qsub8(quadwave8(mul1*k + wave1), lvl1);
If you are only lighting your leds based upon the G force, then create two animations. One that fades the LED from 0 -255 and one that does the opposite.
-determine g force from accelerometer
-see if the g force has changed from its previous state
-if it has changed, then see which direction we need to travel
-run appropriate animation
-rinse and repeat