Jump to content

Speeding up Arduino Prog. Environment


Pwnd2Pwnr

Recommended Posts

Hey-row, Hak5.

I have a rather simple question. If I want to make my Arduino RGB LED strip to fade quicker; can I directly program the speed or do I need a potentiometer instead?

For instance, the fadeSpeed is too fast at 1, but is too slow at 3. I would like something in between. Here is the base code:

// color swirl! connect an RGB LED to the PWM pins as indicated

// in the #defines

// public domain, enjoy!

#define REDPIN 5

#define GREENPIN 6

#define BLUEPIN 3

#define FADESPEED 5 // make this higher to slow down

void setup() {

pinMode(REDPIN, OUTPUT);

pinMode(GREENPIN, OUTPUT);

pinMode(BLUEPIN, OUTPUT);

}

void loop() {

int r, g, b;

// fade from blue to violet

for (r = 0; r < 256; r++) {

analogWrite(REDPIN, r);

delay(FADESPEED);

}

// fade from violet to red

for (b = 255; b > 0; b--) {

analogWrite(BLUEPIN, B);

delay(FADESPEED);

}

// fade from red to yellow

for (g = 0; g < 256; g++) {

analogWrite(GREENPIN, g);

delay(FADESPEED);

}

// fade from yellow to green

for (r = 255; r > 0; r--) {

analogWrite(REDPIN, r);

delay(FADESPEED);

}

// fade from green to teal

for (b = 0; b < 256; b++) {

analogWrite(BLUEPIN, B);

delay(FADESPEED);

}

// fade from teal to blue

for (g = 255; g > 0; g--) {

analogWrite(GREENPIN, g);

delay(FADESPEED);

}

}

This is the de-spaghetti-fied code from ladyada.com. I want to change that damned FADESPEED. In the video; this is just one part of my strip (excuse the mess, my brother has too many kids :) ). I have done vast research (or not looking in the right places), but most of the people whom post their "cool led videos" usually never show their breadboard, not to mention what type of modifications that were made to the code to create those effects. I understand it is their programming... and I do not want a hand out, but I am at my wits end on finding the solution.

So, should I get the potentiometer; or can this be done by adding a library to Arduino? Thanks in advance; and Happy New Years!

Edited by Pwnd2Pwnr
Link to comment
Share on other sites

The loop controls the step of the intensity by 1

for (r = 0; r < 256; r++) {
analogWrite(REDPIN, r);
delay(FADESPEED);
}[/CODE]

[color=#282828][font=helvetica, arial, sans-serif]if you want to fade faster you could just edit the loop [/font][/color]

[color=#282828][font=helvetica, arial, sans-serif]e.g. to make it 5x faster[/font][/color]

[CODE]
for (r = 0; r < 256; r +=5) {
analogWrite(REDPIN, r);
}
[/CODE]

Edited by midnitesnake
Link to comment
Share on other sites

I took the comment out of the code; but it goes too quickly. Is there an in between? Perhaps duplicate the code:

}

// fade from teal to blue

for (g = 255; g > 0; g--) {

analogWrite(GREENPIN, g);

//delay(FADESPEED);

}

// fade from teal to blue

for (g = 255; g > 0; g--) {

analogWrite(GREENPIN, g);

//delay(FADESPEED);

}

Edited by Pwnd2Pwnr
Link to comment
Share on other sites

For twice as fast, and insert the delay to create a small wait after each increment.

for (r = 0; r < 256; r+=2) {

analogWrite(REDPIN, r);

delay(FADESPEED);

}

Just keep tinkering...

Duplicating the code wont work

Code above increases intensity, to decrease:

for (r = 255; r > 0; r-=2) {

analogWrite(REDPIN, r);

delay(FADESPEED);

}

Edited by midnitesnake
Link to comment
Share on other sites

So, reversing (r = 255; r > 0; r-=2) { those parameters to r = 0; r < 255; r+=2) { .... got ya :) . Thank you. That is what the doctor ordered.I have been tinkering for a while now and I am still learning it. I now owe you a beer ;)

Edited by Pwnd2Pwnr
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...