Pages: [1]   Go Down
Author Topic: Random RGB  (Read 1061 times)
0 Members and 1 Guest are viewing this topic.
Somewhere in Arizona
Offline Offline
God Member
*****
Karma: 0
Posts: 725
Arduino must be a drug, because I'm addicted!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, I thought I posted this a long time ago, but I can't find any evidence... I guess I'll just post it...

This is my "Random RGB" project... It selects 1 of 9 colors, and then coems up with a random time to display that color. You use the "Color Finder" to find out the falues you want your colors to be. Then you put those values in the actual "Random RGB", and you're set!

As always, I love feedback (good or bad), as long as it is helpful, and not just mean.

Color Finder
Code:
// This is the RGB value finder. Use this to find the red, green, and blue values of your colors.
// Written by Jeremy Carlson.
// Known as Jeremy1998 on the Arduino Forums.

int redPot = 0;
int greenPot = 1;      
int bluePot = 2;

int redLed = 11;       
int greenLed = 10;
int blueLed = 9;

int redVal;
int greenVal;
int blueVal;

void setup()
{
 Serial.begin(9600);

 pinMode(redLed, OUTPUT);  
 pinMode(greenLed, OUTPUT);  
 pinMode(blueLed, OUTPUT);  
}

void loop()
{
 redVal = analogRead(redPot);
 redVal = map(redVal, 0, 1023, 0, 255);
 greenVal = analogRead(greenPot);
 greenVal = map(greenVal, 0, 1023, 0, 255);
 blueVal = analogRead(bluePot);
 blueVal = map(blueVal, 0, 1023, 0, 255);  
 
 Serial.print("Red:");
 Serial.print(redVal);
 Serial.print(",");
 Serial.print("Green:");
 Serial.print(greenVal);
 Serial.print(",");
 Serial.print("Blue:");
 Serial.println(blueVal);
 
 analogWrite(redLed, redVal);
 analogWrite(greenLed, greenVal);
 analogWrite(blueLed, blueVal);  
 
 delay(25);
}

Random RGB
Code:
// This is the Random RGB Led coloring system. It chooses a random color to display on the RGB led.
// Written by Jeremy Carlson.
// Known as Jeremy1998 on the Arduino Forums.

int redLed = 11;
int greenLed = 10;
int blueLed = 9;

long randNumb;
long randTime;

void setup()
{
 pinMode(redLed, OUTPUT);
 pinMode(greenLed, OUTPUT);
 pinMode(blueLed, OUTPUT);
}

void red()
{
 analogWrite(redLed, 255);
 analogWrite(greenLed, 0);
 analogWrite(blueLed, 0);  
}  

void green()
{
 analogWrite(redLed, 0);
 analogWrite(greenLed, 255);
 analogWrite(blueLed, 0);  
}  

void blue()
{
 analogWrite(redLed, 0);
 analogWrite(greenLed, 0);
 analogWrite(blueLed, 255);  
}  

void yellow()
{
 analogWrite(redLed, 255);
 analogWrite(greenLed, 255);
 analogWrite(blueLed, 0);  
}  

void orange()
{
 analogWrite(redLed, 255);
 analogWrite(greenLed, 35);
 analogWrite(blueLed, 255);  
}  

void pink()
{
 analogWrite(redLed, 255);
 analogWrite(greenLed, 0);
 analogWrite(blueLed, 162);  
}  

void purple()
{
 analogWrite(redLed, 88);
 analogWrite(greenLed, 0);
 analogWrite(blueLed, 112);  
}  

void bluegreen()
{
 analogWrite(redLed, 0);
 analogWrite(greenLed, 144);
 analogWrite(blueLed, 255);  
}  

void white()
{
 analogWrite(redLed, 255);
 analogWrite(greenLed, 255);
 analogWrite(blueLed, 255);  
}  

void loop()
{
 randNumb = random(1, 10);      // Generate a random number between 1 and 10
 randTime = random(250, 1001);  // Generate a random number between 250 and 1000
 
 if(randNumb == 1){
  red();
 }  
 if(randNumb == 2){
  green();
 }
 if(randNumb == 3){
  blue();
 }
 if(randNumb == 4){
  yellow();
 }
 if(randNumb == 5){
  orange();
 }
 if(randNumb == 6){
  pink();
 }
 if(randNumb == 7){
  purple();
 }
 if(randNumb == 8){
  bluegreen();
 }
 if(randNumb == 9){
  white();
 }
      
 delay(randTime);
}
Logged

Somewhere in Arizona
Offline Offline
God Member
*****
Karma: 0
Posts: 725
Arduino must be a drug, because I'm addicted!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Love all of the feedback so far! (SARCASM!!!)
Logged

Somewhere in Arizona
Offline Offline
God Member
*****
Karma: 0
Posts: 725
Arduino must be a drug, because I'm addicted!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nobody likes it???
Logged

Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 138
Power Level is futile (if < 9 000)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I didn't receaved my Arduino from the mail yet.
I'm going to give you feedback maybe this wednesday.  smiley-wink

Care to explain how does this work, in details?  smiley-grin
(it display the color on the pc?)
« Last Edit: October 03, 2010, 12:29:41 pm by kraig » Logged

Somewhere in Arizona
Offline Offline
God Member
*****
Karma: 0
Posts: 725
Arduino must be a drug, because I'm addicted!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It displays on an RGB led conneted to pins 11, 10, and 9.

SENIOR MEMBER!!!!!
« Last Edit: October 03, 2010, 05:32:11 pm by Jeremy1998 » Logged

Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 138
Power Level is futile (if < 9 000)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

man, I should have read the void setup  ;D
The first code give you the 3 RGB values that is displayed by your RGB led and who was set by 3 variables resistors?
« Last Edit: October 03, 2010, 05:40:12 pm by kraig » Logged

Somewhere in Arizona
Offline Offline
God Member
*****
Karma: 0
Posts: 725
Arduino must be a drug, because I'm addicted!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah... I think...

The firat part has an RGB Led, 3 Pots, and the serial monitor. You turn the pots to adjust the brightness of the led. It displays these values in the serial monitor.
Logged

Somewhere in Arizona
Offline Offline
God Member
*****
Karma: 0
Posts: 725
Arduino must be a drug, because I'm addicted!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow!!! 1 freaking person gives a s**t about my project... Feels great...
Logged

United States (Texas)
Offline Offline
God Member
*****
Karma: 2
Posts: 525
Arduino socks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

nicely done
Logged

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

Great i may use this to light up a project I'm working on this looks like just the right thing to get me started.
Logged

New York
Offline Offline
Edison Member
*
Karma: 1
Posts: 1023
E != m*c^2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some time back I did this with an added smoothness - every time a new color was generated, instead of jumping right to that color, a for loop incremented the rgb values until it got there - put a little paper box over it, and it made a pretty cool mood-light. You should try appending that to your code.
Logged

Somewhere in Arizona
Offline Offline
God Member
*****
Karma: 0
Posts: 725
Arduino must be a drug, because I'm addicted!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Shouldn't be too hard... A couple of if statements and +5 or -5... Ill give it a try...
Logged

Pages: [1]   Go Up
Jump to: