Go Down

Topic: Is there an easier way to do all of this? (Read 1 time) previous topic - next topic

AWOL

Code: [Select]
channel 0 is ouptuts 0,1,2 channel 1 is outputs 3,4,5 channel 2 is outputs 6,7,8 channel 3 is outputs 9,10,11 channel 4 is outputs 12,13,14
There's a very simple formula in there, screaming to be let out.

Increments may look cool, but they have a nasty side-effect, which you'll find when you come to try the code out.
Best to anticipate it though.

Yes, you're right, I do like tables.
They allow a degree of flexibility if you decide to change your wiring that arithmetic may not.
And I really would not worry about speed where these values are concerned.

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PeterH


Code: [Select]

switch(chan)
181. {
182. case 0:
183. r = 0; // 0
184. g = r++; // 1
185. b = g++; // 2
186. break; // I'll admit, I thought the increments looked a lot cooler than r=0, g=1, b=2 (yes, I am a bit immature)


The uncool version does have the advantage of giving you the right answer, though.
Fortunately, when you get fed up with debugging the 'cool' version you can replace the whole thing with :
Code: [Select]

r = chan/3;
g = r + 1;
b = g + 1;
I only provide help via the forum - please do not contact me for private consultancy.

AWOL

And when you get bored of debugging that, use a multiplication instead of a division
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dpmattox

Got rid of that ugly math, thanks guys, and sortData() is a result of complaints about invalid Char to int conversions. data[chan][0] = atoi(red); doesn't work.

AWOL

#24
Sep 11, 2012, 11:13 pm Last Edit: Sep 11, 2012, 11:16 pm by AWOL Reason: 1
Quote
data[chan][0] = atoi(red); doesn't work.

What does that mean?
It doesn't like data because rows and cols are declared after you used them?

Or because of this
Code: [Select]
chan = atoi(chan); ?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up