Welcome to Multi-Rotor UK. Please login or sign up.

Monday,January 20, 2020, 08:28:31

Login with username, password and session length

Shoutbox

Rares Gosav:
17 Jan 2020 17:44:22
Hi guys and happy new year!!!
ched:
01 Jan 2020 00:12:50
Happy new year everyone, happy flying.  :beer2: :beer2:
Gaza07:
31 Dec 2019 17:06:13
Happy new year all hope 2020 is a cracking year for you  :beer2:
ched:
25 Dec 2019 00:00:49
Happy Christmas to everyone.
apollo7:
24 Dec 2019 13:50:56
Seasons greetings to all on this forum have a good one ;)
ched:
21 Dec 2019 17:58:42
Have a great time DB. Look forward your projects in 2020.  :beer2:
hoverfly:
21 Dec 2019 16:59:17
Have a good one D.B. ~~ :beer2: :beer2: :beer2:
DarkButterfly:
21 Dec 2019 16:14:27
 :beer2:
DarkButterfly:
21 Dec 2019 16:13:44
Tbh I've been really busy, not had much time to fly anything and with conditions being crap, hopefully in the new year I'll have some new projects on the go, mostly to do with HAM radio, will certainly fly again soon. FTR I hate FB too   :D Merry Christmas
Gaza07:
21 Dec 2019 15:21:30
Merry Christmas  :beer2:
Members
Stats
  • Total Posts: 197461
  • Total Topics: 19924
  • Online Today: 15
  • Online Ever: 530
  • (Tuesday,June 26, 2012, 08:34:46 )
Users Online
Users: 0
Guests: 8
Total: 8

Theme Changer





thumbnail

3d - Printworx

Printing 3d Forum

Arduino RGB colour fader

Started by teslahed, Thursday,July 05, 2012, 13:46:14

Previous topic - Next topic

teslahed

Thought I'd post up some details of the only successful arduino project I've ever done.

I wanted to make a RGB LED colour fader with possible strobe and sound sensitive effects. So far I've got the colour fading working. You can set the rate at which each of the 3 colours (Red, Green, Blue) varies from minimum to maximum creating all the other colours in between as the 3 go in and out of phase. You can set the light to white if you make all 3 colours stop varying in intensity whilst they are at maximum points.

The objective of the project was just to gain some experience with power LEDs and basic arduino programming - I've not done any computer programming before.





//Written by Chris Telford hacked together from numerous other examples feel free to use and abuse this crappy code as you see fit.
//this varies the rate of change on 3 different LED colours based on readings from 3 potentiometers so that each colour can be held at a fixed brightness or set to oscilate up and down in brightness level at a given rate
//I aim to get it to respond to microphone input.
//05/03/2012


int sensorValueRed = 0; //store the value from the potentiometer
int brightnessRed = 0;    // how bright the LED is
int fadeAmountRed = 5;    // how many points to fade the LED by
int ledPinRed = 3;      //pin LED is attached to
int sensorPinRed = 0;   //pin for the potentiometer
int directionFlagRed = 1; //direction up or down of led brightness ramping

int sensorValueGreen = 0; //store the value from the potentiometer
int brightnessGreen = 0;    // how bright the LED is
int fadeAmountGreen = 5;    // how many points to fade the LED by
int ledPinGreen = 5;      //pin LED is attached to
int sensorPinGreen = 1;   //pin for the potentiometer
int directionFlagGreen = 1; //direction up or down of led brightness ramping

int sensorValueBlue = 0; //store the value from the potentiometer
int brightnessBlue = 0;    // how bright the LED is
int fadeAmountBlue = 6;    // how many points to fade the LED by
int ledPinBlue = 6;      //pin LED is attached to
int sensorPinBlue = 2;   //pin for the potentiometer
int directionFlagBlue = 1; //direction up or down of led brightness ramping

void setup() 

{
  pinMode(ledPinRed, OUTPUT);    //declare Red LED pin as output
  pinMode(ledPinGreen, OUTPUT);  //declare Green LED pin as output
  pinMode(ledPinBlue, OUTPUT);   //declare Blue LED pin as output
   
  Serial.begin(57600);           //start serial communications
}

void loop() 

{
sensorValueRed = analogRead(sensorPinRed);                                                 //read the value from the sensorPinRed as sensorValueRed
fadeAmountRed = sensorValueRed/50;                                                         //fadeAmountRed is sensorValueRed/50
                                                                                             
   if (brightnessRed <=19) {directionFlagRed = 1;}                                           // reverse direction flag when brightness is out of bounds
   else if(brightnessRed >=239) {directionFlagRed = 0;}                                      // reverse direction flag when brightness is out of bounds                             
   
   if (directionFlagRed == 1) {brightnessRed = brightnessRed + fadeAmountRed;}               //if direction flag positive then count up brightness by fadeAmountRed points taken from pot
   else if (directionFlagRed == 0) {brightnessRed = brightnessRed - fadeAmountRed;}          //if direction flag negative then count down brightness by fadeAmountRed points taken from pot

   analogWrite(ledPinRed, brightnessRed);                                                    //write the brightnessRed to the ledPinRed
     


sensorValueGreen = analogRead(sensorPinGreen);                                             //read the value from the sensorPinGreen as sensorValueGreen
fadeAmountGreen = sensorValueGreen/50;                                                     //fadeAmountGreen is sensorValueGreen/50
 
   if (brightnessGreen <19) {directionFlagGreen = 1;}                                        // reverse direction flag when brightness is out of bounds
   else if(brightnessGreen >239) {directionFlagGreen = 0;}                                   // reverse direction flag when brightness is out of bounds
   
   if (directionFlagGreen == 1) {brightnessGreen = brightnessGreen + fadeAmountGreen;}       //if direction flag positive then count up brightness by fadeAmountGreen points taken from pot
   else if (directionFlagGreen == 0) {brightnessGreen = brightnessGreen - fadeAmountGreen;}  //if direction flag negative then count down brightness by fadeAmountGreen points taken from pot
 
   analogWrite(ledPinGreen, brightnessGreen);                                                //write the brightnessGreen to the ledPinGreen
       
       
       
       
sensorValueBlue = analogRead(sensorPinBlue);                                               //read the value from the sensorPinBlue as sensorValueBlue
fadeAmountBlue = sensorValueBlue/50;                                                       //fadeAmountBlue is sensorValueBlue/50
 
   if (brightnessBlue <=19) {directionFlagBlue = 1;}                                         // reverse direction flag when brightness is out of bounds
   else if(brightnessBlue >=239) {directionFlagBlue = 0;}                                    // reverse direction flag when brightness is out of bounds
   
   if (directionFlagBlue == 1) {brightnessBlue = brightnessBlue + fadeAmountBlue;}           //if direction flag positive then count up brightness by fadeAmountBlue points taken from pot
   else if (directionFlagBlue == 0) {brightnessBlue = brightnessBlue - fadeAmountBlue;}      //if direction flag negative then count down brightness by fadeAmountBlue points taken from pot
     
   analogWrite(ledPinBlue, brightnessBlue);                                                  //write the brightnessBlue to the ledPinBlue
   
delay(1);   
       

  Serial.println ("TICK!");                                                                 //debug code with 'TICKS' every new fade amount.
  Serial.print ("brightnessRed ");
  Serial.println(brightnessRed);
  Serial.print ("fadeAmountRed ");
  Serial.println(fadeAmountRed);
  Serial.print ("brightnessGreen ");
  Serial.println(brightnessGreen);
  Serial.print ("fadeAmountGreen ");
  Serial.println(fadeAmountGreen);
  Serial.print ("brightnessBlue ");
  Serial.println(brightnessBlue);
  Serial.print ("fadeAmountBlue ");
  Serial.println(fadeAmountBlue);
  Serial.println ("TICK ");   
}
One circlip short of a quadcopter.
 1 lobe short of an antenna.

teslahed

Anyone familiar with coding the arduino could probably point out quite a few mistakes with my code - i am sure there are better ways to do what i did if you know what you are doing. I was just happy when i got it working at all.
One circlip short of a quadcopter.
 1 lobe short of an antenna.

Gaza07

Wow those leds are bright now I see why you wouldn't point the camera at them in your other post,
my knowledge of electronics is very basic but, Ive always been interested in it and used to build some of the maplin kits years ago then, I had a family to and hobbies took a back seat for some time but multi rotor flying has sparked my interest in electronics of again, I used to do a little programming years ago for a BBs system I used to run which involved creating small basic type programs that were then compiled but as for other languages I have no knowledge at all, so im a total noob really  ::)
Thanks for sharing your code and if I do mange to write some thing I will also share it  ~~