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

Tuesday,June 25, 2019, 00:20:32

Login with username, password and session length

Shoutbox

ched999uk:
22 Jun 2019 14:56:09
who??  :laugh:
Slayer23:
22 Jun 2019 11:48:18
guess whos back
 :laugh: :laugh:
atomiclama:
18 Jun 2019 10:41:40
Luckily wasn't that far out and managed to bring it back LOS  :sweating: So now need to coat the reset of my kit. :laugh:
atomiclama:
18 Jun 2019 10:40:51
Stuff it, yesterday I was going to fly rain or no rain, guess what it was raining, still went out. Quad is all conformal coated so I thought lets give it ago. Quad was fine VRX strapped to the top of me goggles wasn't Didn't think to coat that.
Bad Raven:
12 Jun 2019 19:43:40
You didn't break rules, its just difficult to follow lengthy posts here, better in a proper thread.
ChrisKz:
12 Jun 2019 18:43:54
Thanks Ched ... BR . sorry if I broke rules
ched999uk:
12 Jun 2019 18:41:18
Cheers BR
Bad Raven:
12 Jun 2019 18:39:58
Shout box not ideal for discussions!  BMFA affiliated clubs do not HAVE to force achievement tests no more than they HAVE to allow any specific type of model. There are plane only, there are Heli only, etc.
ched999uk:
12 Jun 2019 18:30:21
Seems to be a pv club in IP6 here: https://www.facebook.com/groups/1483581111957310/
ChrisKz:
12 Jun 2019 17:38:49
I'm with u on that one ched .  I'm in no hurry to purchase one yet , I like to do a little research as to what is out there . Insurance is a must anyways . I shoot pcps so always covered
Members
  • Total Members: 8046
  • Latest: ayush05
Stats
  • Total Posts: 195996
  • Total Topics: 19717
  • Online Today: 55
  • Online Ever: 530
  • (Tuesday,June 26, 2012, 08:34:46 )
Users Online
Users: 0
Guests: 20
Total: 20

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.





//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  ~~