Go Down

Topic: Finally made a glowing candle :) (RGB one!) (With Video?) (now with code! LOL) : (Read 826 times) previous topic - next topic

cjdelphi

http://www.youtube.com/watch?v=mUN7MHPEcDo

and i only had 1 issue with the code from start to finish :D - getting used to this C/C++ thingy now... still wish i had a pascal compiler though lol

dxw00d

Theoretically, Pascal would be possible using GNU Pascal.

cjdelphi

Great, but it's a little late, i've just about got the knack of it to write large portions of code without refering to help files.

So, meh why make it any more difficult for myself.

cjdelphi


cjdelphi

Code: [Select]

int ledPin1 = 9; 
int ledPin2 = 10;
int ledPin3 = 11;// LED connected to digital pin 9
int val = 0;         // variable to store the read value
boolean firstcycle = false;

void setup()
{
  pinMode(ledPin1, OUTPUT);   // sets the pin as output
  pinMode(ledPin2, OUTPUT);   // sets the pin as output
  pinMode(ledPin3, OUTPUT);   // sets the pin as output
 
}

void loop()
{
  int n;
  int n2;
  int n3;
   delay(3000);
   digitalWrite(ledPin1,LOW);
   digitalWrite(ledPin2,LOW);
   digitalWrite(ledPin3,LOW);   
//  val = analogRead(analogPin);   // read the input pin
  n2=255;
  if (firstcycle==false) {
  for (n=0; n<255; n++)
  {
     analogWrite(ledPin1, n);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
     delay(15);
     n2--;
    }
  }


  n2=0;

  for (n=255; n>0;)
  {
     analogWrite(ledPin1, n);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
     analogWrite(ledPin2, n2);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255     
     delay(15);
     n--;
     n2++;
  }


  n2=255;
  for (n=0; n<255;)
  {
     
     analogWrite(ledPin2, n2);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
     analogWrite(ledPin3, n);
     delay(15);
     n++;
     n2--;
  }



for (n=255; n>0;)
  {
     analogWrite(ledPin3, n);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
     analogWrite(ledPin1, n2);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255     
     delay(15);
     n--;
     n2++;
  }
 
  firstcycle=true;

}



your thoughts :)

florinc

Quote
still wish i had a pascal compiler though

And hence the user name :)

danimath



your thoughts :)


OK - here are my two cent: If it works for you and you are satisfied, then it's OK. It's (mostly ;)) well formatted - this helps to understand the program. I have only two remarks:

1. the for loops
Code: [Select]
for (n=255; n>0;) are a little bit unusual. Why did you put the n-- into the loop and not into the for statement?

2. I think the part "if (firstcycle==false)" may go into the setup function (without the "if"). Then you can spare a boolean (not really necessary here, but memory on ┬ÁC is tight  ;)).

Thumbs up!

best regards
Andreas
http://danimathblog.blogspot.com

#define true '/'/'/'
#define false '-'-'-'

Nick Gammon

It looks pretty realistic. Well done!

Of course, normal candles aren't multi-colour, that's over egging the pudding, eh? But a nice effect.
http://www.gammon.com.au/electronics

Go Up