Created
October 26, 2010 06:59
-
-
Save paultag/646452 to your computer and use it in GitHub Desktop.
Throbber ( Take Deux )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* "Throb" effect ( Part Deux ) | |
* | |
* Paul Tagliamonte, 2010. ( Peace, Love and C++, baby ) | |
* | |
* This code is released under the Bacon license. | |
* If you like this code enough, consider sending me bacon. | |
* | |
* That or GPL-3+. | |
* | |
*/ | |
int ledPin = 13; // cute LED built into the Arduino | |
int adder = 1; // how much to jump by. | |
// This will be inverted later. | |
int slope = 15; // y = (slope) x | |
int accumulator = 0; // part of bresie's algorithm | |
int cycle = 10; // duty ( hehehehe, doodie ) cycle | |
int on = 5; // How long "on" is per cycle. | |
int bottom = 1; // What "off" is | |
void setup() { pinMode(ledPin, OUTPUT); } // one line, dawg. | |
void loop() { | |
/* | |
* Credit where credit is due: | |
* The following is an adaption of Bresenham's line algorithm. | |
* | |
* To future CS students, as well as current CS students: | |
* Please pay attention in class. You never know when the most | |
* inconsequential algorithm for the most obscure and backwards | |
* example will come in handy. This algorithm was originally | |
* to draw lines. | |
* | |
* Now, the reason I use this is one big reason and one big reason | |
* only: It does not use division or floating point numbers to do | |
* computation. This was by design ( since such operations would | |
* bog down a CPU by a large factor when done over 10,000,000,000 | |
* times ). Since the Arduino sucks with floating point numbers, | |
* and since it's a cute ARM processor, this is a perfect fit. | |
* | |
* Stay in school, kids. Listen to your parents. | |
* | |
* Oh yes, and go to class. For the love of christ, go to class. | |
* | |
*/ | |
accumulator = accumulator + 1; // on cycle length | |
if ( accumulator > slope ) { // if we've gone far enough X to jump a Y | |
accumulator = 0; // then: - reset the counter | |
on = on + adder; // - pop the "line" up one "Y" | |
if ( on >= cycle || on <= bottom ) | |
adder = -adder; // if we're at the border, invert the adder for the next go-around. | |
} | |
digitalWrite(ledPin, HIGH); // BRIGHT! | |
delay(on); // Wait for it! | |
digitalWrite(ledPin, LOW); // Darker then my coffee | |
delay(cycle - on); // Wait for it! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment