Pages: 1 2 [3] 4   Go Down
Author Topic: Help on random led coloring?  (Read 4749 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 637
Posts: 34582
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 637
Posts: 34582
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 637
Posts: 34582
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 637
Posts: 34582
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You already know. This bit of code:-
Code:
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?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so what do I put when I write:

Serial.Print("[glow]     [/glow], DEC")
in the loop?
« Last Edit: September 21, 2009, 05:39:21 pm by ikestarm » Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 637
Posts: 34582
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Serial.print(" R - ");
Serial.print(rgb[0] , DEC);
Serial.print(" G - ");
Serial.print(rgb[1] , DEC);
Serial.print(" B - ");
Serial.println(rgb[2] , DEC);
« Last Edit: September 22, 2009, 04:16:55 am by Grumpy_Mike » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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"
« Last Edit: September 21, 2009, 07:15:09 pm by ikestarm » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26526
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 637
Posts: 34582
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: September 22, 2009, 04:18:02 am by Grumpy_Mike » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks it's working great but how do I change this part:

Code:
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?
« Last Edit: September 22, 2009, 07:45:30 pm by ikestarm » Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 637
Posts: 34582
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: 1 2 [3] 4   Go Up
Jump to: