Go Down

Topic: Help on random led coloring? (Read 5282 times) previous topic - next topic

ikestarm

ok, I got it now. How do you mke it so on post #19 the code makes it light only one color and not change through them?

Grumpy_Mike

By using the code in post 26. Or if not the code the idea.

ikestarm

yeah but almost all of the colors made by that code are white and the blue value is always 90-95

Grumpy_Mike

Yes they will be, that's the nature of random numbers.
That's why I offered the advice in reply #20.

ikestarm

How do you make the code in past 19 so it recognizes values?

Grumpy_Mike

What do you mean by
Quote
recognizes values

Do you mean it accepts values over the serial input from the terminal or processing?
If so this thread has some clues:-
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1252747698/all

ikestarm

I mean I want it to know how much the green is shining and same for all the other colors by using the serial monitor. I did it before, but the colors were not random enough. I want to do it with the code in post #19

Grumpy_Mike

You already know. This bit of code:-
Code: [Select]
void RGBCommonLED::updateLED(){
 analogWrite(this->pins[0], rgb[0]);
 analogWrite(this->pins[1], rgb[1]);
 analogWrite(this->pins[2], rgb[2]);
}


Writes the RGB values out to the LED so the rgb[] array has the values you want in them. Am I missing something here?

ikestarm

#38
Sep 22, 2009, 12:39 am Last Edit: Sep 22, 2009, 12:39 am by ikestarm Reason: 1
so what do I put when I write:

Serial.Print("[glow]     [/glow], DEC")
in the loop?

Grumpy_Mike

#39
Sep 22, 2009, 01:47 am Last Edit: Sep 22, 2009, 11:16 am by Grumpy_Mike Reason: 1
Serial.print(" R - ");
Serial.print(rgb[0] , DEC);
Serial.print(" G - ");
Serial.print(rgb[1] , DEC);
Serial.print(" B - ");
Serial.println(rgb[2] , DEC);

ikestarm

#40
Sep 22, 2009, 02:10 am Last Edit: Sep 22, 2009, 02:15 am by ikestarm Reason: 1
I know I'm doing something really stupid right now, but where and how do I place that in the code? It keeps saying: expected constructor, destructor, or conversion type before '.' token

And it says "rgb[0] was not declared in this scope"

AWOL

We're working blind here - can you post your code and tell us what it is you want to do?

If you don't have something like "byte rgb [3];" declared somewhere in scope, your code won't compile.
"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.

Grumpy_Mike

#42
Sep 22, 2009, 11:12 am Last Edit: Sep 22, 2009, 11:18 am by Grumpy_Mike Reason: 1
Place the print code after you have set the values so for example you could put it at the end of the void RGBCommonLED::updateLED(){ definition.

OR

If you want to be able to print from anywhere then move the definition of the rgb[] array so that it is global. That is move it to outside a function to the start of the sketch. Then you can put the print statements anywhere you like,


P.S. Forgot to include a semicolon at the end of all the print lines, now corrected.

ikestarm

#43
Sep 23, 2009, 02:45 am Last Edit: Sep 23, 2009, 02:45 am by ikestarm Reason: 1
Thanks it's working great but how do I change this part:

Code: [Select]
void setup()
{
 Serial.begin(9600);
 randomSeed(analogRead(0));
 testRGB();
}

void testRGB(){
 led1.setRGB(255,0,0);
 led1.updateLED();
 delay(500);
 led1.setRGB(0,255,0);
 led1.updateLED();
 delay(500);
 led1.setRGB(0,0,255);
 led1.updateLED();
 delay(2000);
 return;

}

void loop()
{
 led1.setRandomHue();
 led1.setSat(255);
 led1.setVal(255);
 led1.updateLED();
 delay(3000);
 led1.setRandomColor();
 led1.updateLED();
 delay(1000);
 return;

}


so that there is no "test" and it only show one color, not changing the color?

Grumpy_Mike

Quote
so that there is no "test" and it only show one color, not changing the color?


Take everything in the loop() function and put it in the setup() function.
The loop() function will be empty but you still need it.
Also there is no need to have a return statement at the end of a function.

Go Up