Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Fading RGB LED between colours on: April 05, 2009, 08:30:25 pm
Halley,
That's what I was wondering was how to incorporate his answer into the code I listed.  I'll give it a try and see if I can figure it out...this is the first program I've ever done, so on a bit of a learning curve.  Thanks, will let you know if I run into any problems.
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: Fading RGB LED between colours on: April 05, 2009, 06:18:50 pm
I had a similar question as well....if you don't mind my digging up this thread:

I've got part of my code listed below:
Code:
      analogWrite(rpin, 255);        // LED color white
       analogWrite(gpin, 255);
       analogWrite(bpin, 255);  
       delay(1000);
  
       analogWrite(rpin, 255);        // LED color purple
       analogWrite(gpin, 0);
       analogWrite(bpin, 255);
       delay(1000);

Their are a total of 7 colors set up in this manner, and I want to fade from one to the next.  How would I impliment your fading affect into this?  Any help would be greatly appreciated.
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with specific rgb color, fade and random pick on: April 07, 2009, 04:32:10 am
AlphaBeta, thanks for your input as well.  It's very much appreciated and I also am greatful for you posting additional code as well as it will give me something to study from.  I'll try and upload it to my board and see how it works.  Thanks again.
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with specific rgb color, fade and random pick on: April 06, 2009, 05:17:37 pm
Thanks PA Skins....that fixed it.
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with specific rgb color, fade and random pick on: April 06, 2009, 03:16:35 pm
OK, might have spoke too soon.  Seems the random color selector selects the same pattern of "randomness" once the board has been reset.  I ran it through 5 times, and the "random" gave me purple, purple, orange, blue, then yellow.  Reset the board, ran it five times and got the same "random" colors, in the same order.  
6  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with specific rgb color, fade and random pick on: April 06, 2009, 01:32:49 pm
Thanks a million guys, seems to be working great now.  Here's what I have:
Code:
byte colours[7][3] = {
  // Seven colours 0-6, and
  // each has three components 0-2 for red, green, blue
  255, 255, 255,  // white
  255, 0, 255,  // purple
  0, 0, 255,  // blue
  0, 255, 0,  // green
  255, 255, 0,  // yellow
  255, 153, 0,  // orange
  255, 0, 0,  // red
};

int val=0;                            
int inPin=4;                           // switch connected to pin 4
int rpin=3;
int gpin=5;
int bpin=6;

void setup() {
pinMode (inPin, INPUT);  
}
 
void loop()
{
  val=digitalRead(inPin);
  if (val==LOW)
  
  {
       analogWrite(rpin, 255);        // LED color white
       analogWrite(gpin, 255);
       analogWrite(bpin, 255);  
       delay(3000);
           for (int x=255; x>0; x--) {
           analogWrite(gpin, x);
           delay(10);
            }
  
       analogWrite(rpin, 255);        // LED color purple
       analogWrite(gpin, 0);
       analogWrite(bpin, 255);
       delay(3000);
          for (int x=255; x>0; x--) {
          analogWrite(rpin, x);
          delay(10);
          }

       analogWrite(rpin, 0);          // LED color blue
       analogWrite(gpin, 0);
       analogWrite(bpin, 255);
       delay(3000);
         for (int x=0; x<256; x++) {
         analogWrite(gpin, x);
         delay(10);
          }
         for (int x=255; x>0; x--) {
         analogWrite(bpin, x);
         delay(10);
          }
      
       analogWrite(rpin, 0);          // LED color green
       analogWrite(gpin, 255);
       analogWrite(bpin, 0);
       delay(3000);
         for (int x=0; x<256; x++) {
         analogWrite(rpin, x);
         delay(10);
          }
                
       analogWrite(rpin, 255);        // LED color yellow
       analogWrite(gpin, 255);
       analogWrite(bpin, 0);
       delay(3000);
         for (int x=255; x>153; x--) {
         analogWrite(gpin, x);
         delay(10);
          }

       analogWrite(rpin, 255);        // LED color orange
       analogWrite(gpin, 153);
       analogWrite(bpin, 0);
       delay(3000);
         for (int x=153; x>0; x--) {
         analogWrite(gpin, x);
         delay(10);
          }
      
       analogWrite(rpin, 255);        // LED color red
       analogWrite(gpin, 0);
       analogWrite(bpin, 0);
       delay(3000);
         for (int x=255; x>0; x--) {
         analogWrite(rpin, x);
         delay(10);
          }
          
       analogWrite(rpin, 0);        // All off
       analogWrite(gpin, 0);
       analogWrite(bpin, 0);
    
 int randomVal = random(0, 6);  // Choose a random value, 0-6
 byte redComponent = colours[randomVal][0];
 byte greenComponent = colours[randomVal][1];
 byte blueComponent = colours[randomVal][2];
 analogWrite(rpin, redComponent);
 analogWrite(gpin, greenComponent);
 analogWrite(bpin, blueComponent);
     delay(5000);
  }
  }
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with specific rgb color, fade and random pick on: April 06, 2009, 12:24:40 pm
Thanks to both of you smiley-wink
Halley, do I insert your code after my red color fades out?  Sorry for so many ?'s.
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with specific rgb color, fade and random pick on: April 06, 2009, 10:32:30 am
Thanks, I'll remove the last "if" statement and fix the first one....forgot to change it in the comments.

For the random portion, what I want to do is have the program randomly pick one of the 7 colors I have listed, i.e. white, purple, blue, green, yellow, orange or red and then display that after the red fades out.  I tried to #define each color with a number as I thought it would make it able to randomly pick a color if a number was assigned to it, like:
Code:
#define white 1
#define blue 2
etc.....
then try and make each color it's own void....
Code:
void white() {
.....
but that didn't work at all
Any suggestions?  Thanks again for the help.  
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with specific rgb color, fade and random pick on: April 06, 2009, 08:30:41 am
Thanks CMiYC, works great!  Plus I understood the actual way it was functioning, so made it that much easier to implement ;-)
So, my code is now as follows:

Code:
int val=0;                            
int inPin=4;                           // switch connected to pin 4
int rpin=3;
int gpin=5;
int bpin=6;

void setup()
{
  pinMode (inPin, INPUT);                // declare pushbutton as input
}
 
void loop()
{
  val =digitalRead (inPin);            // read input value
  if (val == LOW) {                    // check if input is high
      
       analogWrite(rpin, 255);        // LED color white
       analogWrite(gpin, 255);
       analogWrite(bpin, 255);  
       delay(3000);
           for (int x=255; x>0; x--) {
           analogWrite(gpin, x);
           delay(10);
            }
  
       analogWrite(rpin, 255);        // LED color purple
       analogWrite(gpin, 0);
       analogWrite(bpin, 255);
       delay(3000);
          for (int x=255; x>0; x--) {
          analogWrite(rpin, x);
          delay(10);
          }

       analogWrite(rpin, 0);          // LED color blue
       analogWrite(gpin, 0);
       analogWrite(bpin, 255);
       delay(3000);
         for (int x=0; x<256; x++) {
         analogWrite(gpin, x);
         delay(10);
          }
         for (int x=255; x>0; x--) {
         analogWrite(bpin, x);
         delay(10);
          }
      
       analogWrite(rpin, 0);          // LED color green
       analogWrite(gpin, 255);
       analogWrite(bpin, 0);
       delay(3000);
         for (int x=0; x<256; x++) {
         analogWrite(rpin, x);
         delay(10);
          }
                
       analogWrite(rpin, 255);        // LED color yellow
       analogWrite(gpin, 255);
       analogWrite(bpin, 0);
       delay(3000);
         for (int x=255; x>153; x--) {
         analogWrite(gpin, x);
         delay(10);
          }

       analogWrite(rpin, 255);        // LED color orange
       analogWrite(gpin, 153);
       analogWrite(bpin, 0);
       delay(3000);
         for (int x=153; x>0; x--) {
         analogWrite(gpin, x);
         delay(10);
          }
      
       analogWrite(rpin, 255);        // LED color red
       analogWrite(gpin, 0);
       analogWrite(bpin, 0);
       delay(3000);
         for (int x=255; x>0; x--) {
         analogWrite(rpin, x);
         delay(10);
          }
  }
    if (val == LOW)
    {
    analogWrite (rpin, 0);
    analogWrite (gpin, 0);
    analogWrite (bpin, 0);
      
      
    }
}
So, now all I need to figure out is how to chose one of these 7 colors at random and display it after it's went through the sequence.  I tried to #define each color and assign it a number, but that didn't work.  As this is my first project, it's definitely teaching me quite a bit  smiley
Thanks for all the help thus far
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with specific rgb color, fade and random pick on: April 05, 2009, 05:31:12 am
Hope this explains a little bit (my first attempt....be gentle)
Code:
int val=0;                            
int inPin=2;                           // switch connected to pin 2
int rpin=3;
int gpin=5;
int bpin=6;

void setup()
{
  pinMode (inPin, INPUT);                // declare pushbutton as input
}
 
void loop()
{
  val =digitalRead (inPin);            // read input value
  if (val == HIGH) {                    // check if input is high
    analogWrite (rpin, 0);
    analogWrite (gpin, 0);
    analogWrite (bpin, 0);
  }
    else
    {
       analogWrite(rpin, 255);        // LED color white
       analogWrite(gpin, 255);
       analogWrite(bpin, 255);  
       delay(1000);
  
       analogWrite(rpin, 255);        // LED color purple
       analogWrite(gpin, 0);
       analogWrite(bpin, 255);
       delay(1000);
  
       analogWrite(rpin, 0);          // LED color blue
       analogWrite(gpin, 0);
       analogWrite(bpin, 255);
       delay(1000);
      
       analogWrite(rpin, 0);          // LED color green
       analogWrite(gpin, 255);
       analogWrite(bpin, 0);
       delay(1000);
      
       analogWrite(rpin, 255);        // LED color yellow
       analogWrite(gpin, 255);
       analogWrite(bpin, 0);
       delay(1000);
      
       analogWrite(rpin, 255);        // LED color orange
       analogWrite(gpin, 153);
       analogWrite(bpin, 0);
       delay(1000);
      
       analogWrite(rpin, 255);        // LED color red
       analogWrite(gpin, 0);
       analogWrite(bpin, 0);
       delay(1000);
    }
}

Not sure how to incorporate the fading from one to the next or to select one of the 7 at random....will keep searching ;-)
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with specific rgb color, fade and random pick on: April 04, 2009, 06:50:15 pm
Unfortunately, no coding....i'm completely new to this.  I've uploaded sketches and changed minor things in code, but never wrote my own.  Hardware wise, would be really simple.  Probably just get a premade Arduino RBBB board or similar, a RGB LED, momentary push switch and that should be pretty much all I need for this project.  Thanks for any input  smiley-wink
12  Forum 2005-2010 (read only) / Syntax & Programs / help with specific rgb color, fade and random pick on: April 04, 2009, 06:24:53 pm
I'm helping a friend with a project and want to use the arduino to accomplish it.  What I want to do is have 7 specific colors displayed from a RGB LED.  On the activation of a switch, it would display color 1 for about 2 seconds, fade to color 2 (maybe a 1-2 second fade time), display for 2 seconds, fade to color 3....and so on.  At the end of the 7th color, pause for a period of maybe 3 seconds, then choose one of those 7 colors at random and display that color until the switch is released or after maybe a 15 second timeout.  Any and all help would be greatly appreciated.
13  Forum 2005-2010 (read only) / Interfacing / Re: Button for Mode Select on: November 18, 2010, 10:18:06 am
Ok, Paul. Thanks again. Most of the tutorials/examples I was reading used button, so I just used that.  Added a delay before counter ++ also, since my switch seems to be excessively sensitive, so acts a little like a debounce function...or just a lazy way to do it. Anyways, works great now and thanks for the help.

Final setup:

Code:
int counter = 0;

int switchPin = 13;

int LEDB = 11;
int LEDG = 10;
int LEDR = 9;


void setup()
{
  pinMode(switchPin, INPUT);
  pinMode(LEDR, OUTPUT);
  pinMode(LEDG, OUTPUT);
  pinMode(LEDB, OUTPUT);
}

void loop() {
  //Handle input
  int switchVal = digitalRead(switchPin);
  if(switchVal == HIGH)
  {
    delay(500);  
    counter ++;
    //Reset count if over max mode number
    if(counter == 8)
    {
      counter = 0;
    }
  }

  else
    //Change mode
    switch (counter) {
    case 1:
      analogWrite(LEDR, 255);
      break;
    case 2:
      analogWrite(LEDR, 127);
      break;
    case 3:
      analogWrite(LEDR, 000);
      analogWrite(LEDB, 255);
      break;
    case 4:
      analogWrite(LEDB, 127);
      break;
    case 5:
      analogWrite(LEDR, 255);
      analogWrite(LEDG, 255);
      analogWrite(LEDB, 255);
      break;
    case 6:  
      analogWrite(LEDR, 127);
      analogWrite(LEDG, 127);
      analogWrite(LEDB, 127);
      break;
    case 7:
      analogWrite(LEDR, 000);
      analogWrite(LEDG, 000);
      analogWrite(LEDB, 000);
      break;
    }
}
14  Forum 2005-2010 (read only) / Interfacing / Re: Button for Mode Select on: November 17, 2010, 12:59:34 pm
Thanks for the quick reply Paul.
Ok, so hopefully I understood what you are telling me and I looked at the examples in the included sketch files for switch statements...hopefully this is correct  :-[

Code:
int counter = 0;

int buttonPin = 13;
int LEDB = 11;
int LEDG = 10;
int LEDR = 9;


void setup()
{
 pinMode(buttonPin, INPUT);
 pinMode(LEDR, OUTPUT);
 pinMode(LEDG, OUTPUT);
 pinMode(LEDB, OUTPUT);
}

void loop() {
  //Handle input
    if(buttonPin == HIGH)
  {
    counter ++;
    //Reset count if over max mode number
    if(counter == 7)
    {
      counter = 0;
    }
  }

  
  //Change mode
  switch (counter) {
  case 1:
    analogWrite(LEDR, 255);
    break;
  case 2:
    analogWrite(LEDR, 127);
    break;
  case 3:
    analogWrite(LEDB, 255);
    break;
  case 4:
    analogWrite(LEDB, 127);
    break;
  case 5:
    analogWrite(LEDR, 255);
    analogWrite(LEDG, 255);
    analogWrite(LEDB, 255);
    break;
  case 6:  
    analogWrite(LEDR, 127);
    analogWrite(LEDG, 127);
    analogWrite(LEDB, 127);
    break;
 }
}
15  Forum 2005-2010 (read only) / Interfacing / Re: Button for Mode Select on: November 17, 2010, 11:36:00 am
First wanted to say thanks for all the input on this thread as it's exactly what I was wanting to do with a mode select switch and some LED patterns.  That said, I'm having troubles getting mine to work correctly and was wondering if someone could offer some input on the code:

Code:
int counter = 1;

int buttonPin = 13;
int LEDB = 11;
int LEDG = 10;
int LEDR = 9;


void setup()
{
 pinMode(buttonPin, INPUT);
 pinMode(LEDR, OUTPUT);
 pinMode(LEDG, OUTPUT);
 pinMode(LEDB, OUTPUT);
}

void loop()
{
  //Handle input
  digitalRead(buttonPin);
  if(buttonPin = HIGH)
  {
    counter + 1;
    //Reset count if over max mode number
    if(counter == 8)
    {
      counter = 1;
    }
  }

  
  //Change mode
  if(counter == 2)
  {
    analogWrite(LEDR, 255);
  }
  
  else if(counter == 3)
  {
    analogWrite(LEDR, 127);
  }
  
  else if(counter == 4)
  {
    analogWrite(LEDB, 255);
  }
  
  else if(counter == 5)
  {
    analogWrite(LEDB, 127);
  }
  
  else if(counter == 6)
  {
    analogWrite(LEDR, 255);
    analogWrite(LEDG, 255);
    analogWrite(LEDB, 255);
  }
    
  else if(counter == 7)
  {
    analogWrite(LEDR, 127);
    analogWrite(LEDG, 127);
    analogWrite(LEDB, 127);
  }
}
  

I'm using a QT100 as the input for the switch if that makes any difference (which i don't think it should since it outputs a high (3vdc in this case) to pin 13 when touched.

Any help would be greatly appreciated.
Pages: [1] 2