Decided to take a break from the G-Meter, installed 36 leds into the front cover of the case for my PC, two strips of 18. What’s generally the best way to run the same code on two strips from one arduino with two separate pins? I tried to double the Gravball example but nothing happens when I upload it. here’s what I have. http://pastebin.com/CkSeZSbL
Basically I want to run the exact same code on both sides, but since this has a bit of randomness built in it wouldn’t be a mirror image. it’d be nice to have different “balls” on each side rather than just plugging both data connections into the same pin to mirror it.
I did a quick scan of your code and also went back to Andrew Tuline’s original sketch. I suggest 3 things…
You only need to define 1 structure same as originally done by Andrew but then create seperate ‘Left’ and ‘Right’ instances of that structure such as…
typedef struct { // Define a structure for the gravs.
int distold;
int distance;
int velold;
int velocity;
int thishue;
} gravs;
gravs mygravsR[numgravsR];
gravs mygravsL[numgravsL];
Change all structure members to remove the ending ‘R’ and ‘L’ example…
from: mygravsL[L].veloldL to: mygravsL[L].velold
Anytime you end up copying a function like you did and substituting ‘L’ for ‘R’ you have to think you should be able to do it within one function but still… it should work.
I think there are some structural issues with your code, but I’m still learning C++ myself so I can’t say definitively. Having said that, there are two things I see that don’t seem quite right to me (I’m a bit surprised you didn’t get any errors when you compiled):
typedef struct { // Define a structure for the gravs.
int distoldR, distoldL;
int distanceR, distanceL;
int veloldR, veloldL;
int velocityR, velocityL;
int thishueR, thishueL;
gravsR, gravsL;
)
First off, the closing parenthesis should be a right curly brace. Also, the gravsR and gravsL should be after the right curly brace. In other words, it should look like this:
typedef struct { // Define a structure for the gravs.
int distoldR, distoldL;
int distanceR, distanceL;
int veloldR, veloldL;
int velocityR, velocityL;
int thishueR, thishueL;
} gravsR, gravsL;
I do think you could make things much easier though. Most of what you duplicated probably doesn’t need to be. Since all of your variables have identical values, you should be able to use the original struct as-is and just create a second instance of it - like this:
typedef struct { // Define a structure for the gravs.
int distold;
int distance;
int velold;
int velocity;
int thishue;
} gravsR, gravsL;
Then your code would be almost identical. These two lines:
mygravsR[R].velocityR = mygravsR[R].veloldR + gravityR*timeincR; // Split gravity math into two lines for simplicity
mygravsL[L].velocityL = mygravsL[L].veloldL + gravityL*timeincL; // Split gravity math into two lines for simplicity
Would then look like this:
mygravsR[R].velocity = mygravsR[R].velold + gravity*timeinc; // Split gravity math into two lines for simplicity
mygravsL[L].velocity = mygravsL[L].velold + gravity*timeinc; // Split gravity math into two lines for simplicity
If you haven’t seen it already, there is a great section of the FastLED documentation that describes various ways to use multiple strips. This should be really helpful to you!
Thank you, I have a different project I’m working on that I did that with, literally just duplicated all the variables and it works perfectly so I thought that might work with this project. I’m great with the hardware and wiring, but I have a lot to learn about coding still.
Playing with Arduino stuff is definitely addictive! My goto board is the Teensy 3.1 but the nice thing about the Arduino ecosystem is there are plenty of great options.
My only problem is that I wish I would’ve paid more attention in my computer science class in high school. Haha. I have tons of ideas for projects, and I can do all the wiring and hardware setup, but I almost always have to go off of someone else’s example sketches if I want to actually finish a project…
@Kyle_Halvorson Just stick around here for a year and your knowledge base will expand along with the library, mine certainly did. Learn by helping others, learn by asking questions, and learn by using functioning blocks of code.