Go to Post It's one thing to post thoughts, guesses, opinions - that's all good ... However, it's [different] to make statements claiming first hand knowledge & facts without actually having first hand knowledge, facts, or accurate information. - Jason Morrella [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Events   CD-Media   CD-Spy   FRC-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 05-02-2012, 06:42 PM
apples000's Avatar
apples000 apples000 is offline
Registered User
no team
 
Join Date: Mar 2012
Rookie Year: 2012
Location: United States
Posts: 216
apples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant future
Arduino RGB LED controller

As a fun off season project, I decided to try to make a light controller for out robot. My idea was to use 3 digital outputs from the Digital Side Car to connect to the Arduino, and have 8 lighting combinations. The arduino's 6 PWM's will control r/g/b on two separate lighting zones. Also, the lights on the second zone will be divided into two separate zones, which can be switched on and off with a relay. I've made the circuit in the attached schematic(replaced the solid state relay w/ a normal one), and I have powered it with a 12 volt supply and have used signal generators I made from a 555 timer, and I am able to get the lights to function the way I want. I am not sure programming the Arduino. I have used them in the past, but I have yet to pick one up from radio shack. (The Radio Shack near me has the Arduino Uno!) I have my program set up with 8 different light zones. The program will go into one of the 8 modes based on the controls from the DSC and certain modes will either have red/blue lights (red/blue alliances), that can be switched by a toggle switch on the robot. The code is designed so that when I tell it to switch modes, it will finish the light sequence it has started. Before I go out and buy the Arduino I want to make sure that my code makes some sense so it would be helpful if somebody could check over my code. I've made this code without ever testing it so I'm sure that there are some mistakes. REDPIN/BLUEPIN/GREENPIN are the lights without the relay, and REDPIN2/BLUEPIN2/GREENPIN2 are lights with the relay.



Code:
//LED Control

//1-in1
//2-in2
//3-r1
//4-in3
//5-g1
//6-b1
//7-relay1
//8-relay2
//9-r2
//10-g2
//11-b2
//12-alliance color selector

//Set PWM pins
#define REDPIN 3
#define GREENPIN 5
#define BLUEPIN 6
#define REDPIN2 9
#define GREENPIN2 10
#define BLUEPIN2 11
//Set Digital Input Pins
#define in1 1
#define in2 2
#define in3 4
#define alliance 12
//Set Signal Light Relays
#define relay1 7
#define relay2 8
#define del 1
//Input Values
int val1 = 0;
int val2 = 0;
int val3 = 0;
int allval = 0;
//Alliance Color r/b vals
int rval = 0;
int bval = 0;

//Light mode from inputs
int lightMode = 0;
//Rainbow counters
int r;
int g;
int b;
int rr;
int gg;
int bb;

void setup() {
  //define pin modes
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
  pinMode(REDPIN2, OUTPUT);
  pinMode(GREENPIN2, OUTPUT);
  pinMode(BLUEPIN2, OUTPUT);
  pinMode(in1, INPUT);
  pinMode(in2, INPUT);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  randomSeed(analogRead(0));
  //This code MAY be needed
  //Serial.begin(9600);

}

void loop() {

  //Read inputs and store them in val
  val1 = digitalRead(in1);
  val2 = digitalRead(in2);
  val3 = digitalRead(in3);
  //Get r/b alliance
  allval = digitalRead(alliance);




  //Determine which light mode is selected

  if (val3 == 0 && val2 == 0)
  {
    if (val1 == 0)
    {
      lightMode = 0;
    }
    else 
    {
      lightMode = 1;
    }
  }
  if (val3 == 0 && val2 == 1)
  {
    if (val1 == 0)
    {
      lightMode = 2;
    }
    else
    {
      lightMode = 3;
    }
  }
  if (val3 == 1 && val2 == 0)
  {
    if (val1 == 0)
    {
      lightMode = 4;
    }
    else
    {
      lightMode = 5;
    }
  }
  if (val3 == 1 && val2 == 1)
  {
    if (val1 == 0)
    {
      lightMode = 6;
    }
    else
    {
      lightMode = 7;
    }
  }
  //Set relays and PWMs depending on light mode

  if (lightMode == 1)
  {
    //rainbow mode
//this sequence will make a rainbow thing
    //Set both relays to on
    digitalWrite(relay1, HIGH);
    digitalWrite(relay2, HIGH);
    //set PWMs
    for (g = 0; g>255; g++){
      analogWrite(REDPIN, 255);
      analogWrite(GREENPIN, g);
      analogWrite(BLUEPIN, 0);

      analogWrite(REDPIN2, 0);
      analogWrite(GREENPIN2, g);
      analogWrite(BLUEPIN2, 255);
      delay(del);
    }

    for (r = 255; r < 1; r = r - 1){
      analogWrite(REDPIN, r);
      analogWrite(GREENPIN, 255);
      analogWrite(BLUEPIN, 0);

      analogWrite(REDPIN2, 0);
      analogWrite(GREENPIN2, r);
      analogWrite(BLUEPIN2, 255-r);
      delay(del);
    }
    for (b = 0; b>255; b++){
      analogWrite(REDPIN, 0);
      analogWrite(GREENPIN, 255-b); //may just be 255?
      analogWrite(BLUEPIN, b);

      analogWrite(REDPIN2, 255-b);
      analogWrite(GREENPIN2, 255);
      analogWrite(BLUEPIN2, 0);
      delay(del);
    }
    for (g = 0; g>255; g++){
      analogWrite(REDPIN, 0);
      analogWrite(GREENPIN, g);
      analogWrite(BLUEPIN, 255);

      analogWrite(REDPIN2, 255);
      analogWrite(GREENPIN2, g);
      analogWrite(BLUEPIN2, 0);
      delay(del);
    }
  }

  if (lightMode == 0)
  {
    //Set both relays on
    digitalWrite(relay1, HIGH);
    digitalWrite(relay2, HIGH);
    //Figure out alliance color values
    if (allval == 0)
    { 
      rval = 0;
      bval = 255;
    }

    if (allval == 1)
    {
      rval = 255;
      bval = 0;
    }




    analogWrite(REDPIN, rval);
    analogWrite(GREENPIN, 0);
    analogWrite(BLUEPIN, bval);

    analogWrite(REDPIN2, rval);
    analogWrite(GREENPIN2, 0);
    analogWrite(BLUEPIN2, bval);




  }

  if (lightMode == 2)
  {
    //Alliance 2 (Flashing Singal Light alliance color)
     //Figure out alliance color values
    if (allval == 0)
    { 
      rval = 0;
      bval = 255;
    }

    if (allval == 1)
    {
      rval = 255;
      bval = 0;
    }
  for(r = 0; r>1000; r++){
  analogWrite(REDPIN, rval);
  analogWrite(GREENPIN, 0);
  analogWrite(BLUEPIN, bval);
  
  analogWrite(REDPIN2, rval);
  analogWrite(GREENPIN2, 0);
  analogWrite(BLUEPIN2, bval);
  
  if (r < 500)
    {
      digitalWrite(relay1, HIGH);
      digitalWrite(relay2, LOW);
    }
  if (r > 500)
  {
    digitalWrite(relay1, LOW);
    digitalWrite(relay2, HIGH);
  }
  
  }  
  
  
  }
  if (lightMode == 3)
  {
    //Autonomous (All yellow)
  analogWrite(REDPIN, 255);
  analogWrite(GREENPIN, 255);
  analogWrite(BLUEPIN, 0);
  
  analogWrite(REDPIN2, 255);
  analogWrite(GREENPIN2, 255);
  analogWrite(BLUEPIN2, 0);
  
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, LOW);
  }
  if (lightMode == 4)
  {
    //Autonomous 2 (Yellow w/ flashing signal light)
     for(r = 0; r>1000; r++){
  analogWrite(REDPIN, 255);
  analogWrite(GREENPIN, 255);
  analogWrite(BLUEPIN, 0);
  
  analogWrite(REDPIN2, 255);
  analogWrite(GREENPIN2, 255);
  analogWrite(BLUEPIN2, 0);
  
  if (r < 500)
    {
      digitalWrite(relay1, HIGH);
      digitalWrite(relay2, LOW);
    }
  if (r > 500)
  {
    digitalWrite(relay1, LOW);
    digitalWrite(relay2, HIGH);
  }
  }
  if (lightMode == 5)
  {
    //Red and Blue!
     for(r = 0; r>1000; r++){

  
  if (r < 500)
    {
      digitalWrite(relay1, HIGH);
      digitalWrite(relay2, LOW);
  analogWrite(REDPIN, 0);
  analogWrite(GREENPIN, 0);
  analogWrite(BLUEPIN, 255);
  
  analogWrite(REDPIN2, 255);
  analogWrite(GREENPIN2, 0);
  analogWrite(BLUEPIN2, 0);
  
    }
  if (r > 500)
  {
    digitalWrite(relay1, LOW);
    digitalWrite(relay2, HIGH);
    
  analogWrite(REDPIN, 255);
  analogWrite(GREENPIN, 0);
  analogWrite(BLUEPIN, 0);
  
  analogWrite(REDPIN2, 0);
  analogWrite(GREENPIN2, 0);
  analogWrite(BLUEPIN2, 255);
  }
  }
  if (lightMode == 6)
  {
  analogWrite(REDPIN, 0);
  analogWrite(GREENPIN, 255);
  analogWrite(BLUEPIN, 0);
  
  analogWrite(REDPIN2, 0);
  analogWrite(GREENPIN2, 255);
  analogWrite(BLUEPIN2, 0);
  }
  if (lightMode == 7)
  {
    //Alliance color with white signal light
        if (allval == 0)
    { 
      rval = 0;
      bval = 255;
    }

    if (allval == 1)
    {
      rval = 255;
      bval = 0;
    }
  analogWrite(REDPIN, rval);
  analogWrite(GREENPIN, 0);
  analogWrite(BLUEPIN, bval);
  
  analogWrite(REDPIN2, 255);
  analogWrite(GREENPIN2, 255);
  analogWrite(BLUEPIN2, 255);
  }


  }}}
Sorry for the long post
Attached Thumbnails
Click image for larger version

Name:	RGB LED.png
Views:	114
Size:	11.9 KB
ID:	12713  

Last edited by apples000 : 05-02-2012 at 06:43 PM. Reason: Forgot to attach file
  #2   Spotlight this post!  
Unread 05-02-2012, 07:28 PM
DRH2o's Avatar
DRH2o DRH2o is offline
Registered User
AKA: Dan Waters
FRC #1598 (Team Talon)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Danville, VA
Posts: 135
DRH2o is a glorious beacon of lightDRH2o is a glorious beacon of lightDRH2o is a glorious beacon of lightDRH2o is a glorious beacon of lightDRH2o is a glorious beacon of lightDRH2o is a glorious beacon of light
Re: Arduino RGB LED controller

Sounds cool. My son is a 1st year at UVA and his Rodman Engineering group is making a Rubics Cube that will stand 6 feet tall on it's corner with led lit panels and can be solved by pushing buttons to "rotate" the parts of the cube. It is being controled with a front end program running on a computer passing data through an old ifi interface passing data wireless to the ifi robot controller passing data through the serial interface to an arduino. They just got approval for this to be on display around the engineering school once it is complete next fall.

Maybe I can see what they did once exams are over.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:46 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi