Pages: [1]   Go Down
Author Topic: Finally made a glowing candle :) (RGB one!) (With Video?) (now with code! LOL) :  (Read 801 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Faraday Member
**
Karma: 30
Posts: 2507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



and i only had 1 issue with the code from start to finish smiley-grin - getting used to this C/C++ thingy now... still wish i had a pascal compiler though lol
« Last Edit: April 23, 2012, 09:40:11 am by cjdelphi » Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Theoretically, Pascal would be possible using GNU Pascal.
Logged

Offline Offline
Faraday Member
**
Karma: 30
Posts: 2507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Faraday Member
**
Karma: 30
Posts: 2507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

But did you like the effect? too slow? too fast?
Logged

Offline Offline
Faraday Member
**
Karma: 30
Posts: 2507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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 smiley
Logged

0
Offline Offline
Edison Member
*
Karma: 8
Posts: 1411
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
still wish i had a pascal compiler though
And hence the user name smiley
Logged

Hannover, Germany
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


your thoughts smiley

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

1. the for loops
Code:
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  smiley-wink).

Thumbs up!

best regards
Andreas
Logged

http://danimathblog.blogspot.com

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

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 506
Posts: 19139
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Pages: [1]   Go Up
Jump to: