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

Friday,March 29, 2024, 00:38:33

Login with username, password and session length

Shoutbox

Bad Raven:
26 Mar 2024 08:41:05
 :(
Andy7:
25 Mar 2024 14:49:21
An excess of work and rain.  :thumbdown:
Bad Raven:
23 Mar 2024 18:12:38
Almost a personal Blog, it would seem. LOTS of members, but NO posts.  :-/   :shrug:
Gaza07:
06 Mar 2024 16:59:49
Anyone still here  :shrug:
ched:
24 Dec 2023 11:48:48
Hope you all have a Great Christmas and a happy New Year.
Bad Raven:
20 Dec 2023 06:17:47
 ~~   :beer2: 
Gaza07:
19 Dec 2023 22:20:27
Merry Christmas All  :beer2:
Bad Raven:
01 Dec 2023 06:59:57
New Simulator Section started!   :beer2:
Bad Raven:
17 Jun 2023 06:52:23
Yes, smaller, same as lots of things as time passes.
Andy7:
08 Jun 2023 22:49:18
 ~~
Members
Stats
  • Total Posts: 201,420
  • Total Topics: 20,260
  • Online today: 31
  • Online ever: 530
  • (Tuesday,June 26, 2012, 08:34:46 )
Users Online
Users: 0
Guests: 22
Total: 22

Theme Changer





3d - Printworx

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.

Red Green Blue LED strobing effect

Red Green Blue LED window test

//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  ~~
[url="https://www.youtube.com/channel/UCN6zN99iLCIJea5FCQPKf_g"]YouTube[/url]   [url="https://www.printing-3d.co.uk"]printing-3d[/url]  [url="https://www.thingiverse.com/Gaza07/about"]Thingiverse[/url]  [url="https://www.3d-printworx.co.uk"]3d-printworx[/url]