Hey there teensy fans.
Here is a snippet of code from the tutorial (8 bit) that I've reformatted into a format that has a lot of "tutorial advantages".
Clarity of form.
I've been a programmer / designer now for what, 45 years? Has it been that long? Yep. Since age 14. At first, like most-everyone, I tended to follow the programming style of whatever examples (or the famous Kerningham & Richie 'C' book) were at hand. However, in the intervening years, I've taken to using both line-oriented, indent-oriented formatting AND column oriented form.
It makes it so much easier to read the code, to discern in this case what-all is being attempted. Especially the analogWrite()... delay() repetitions in loop().
I recommend this format. It definitely aids both debugging the code, but also explaining to others how it works. Moreover, it doesn't take very much overhead to do, while you're entering code. In fact, it saves a LOT of time in many cases, both from squashing bugs that are hard to see otherwise, mistakes that you miss, and because single-lines can be copy-pasted, yet do multiple things.
Hope all y'all agree.
But if not, write back!
GoatGuy (first post)
PS: now that I've reviewed how this site reformats things, I see that all multiple-space-characters are chewed up. DARN! Ah... learned to use the [ code ] block. It preserves spaces.
Here is a snippet of code from the tutorial (8 bit) that I've reformatted into a format that has a lot of "tutorial advantages".
Clarity of form.
Code:
/* ---------------------------------------------------------------------- */
/* Set up constants to define pins. Do this "at the top" so that it */
/* flows thru the rest of the code parametrically. */
/* ---------------------------------------------------------------------- */
int redPin = 12;
int greenPin = 15;
int bluePin = 14;
/* ---------------------------------------------------------------------- */
/* Set the defined pins to OUTPUT mode, so they can be modulated by the */
/* code herein. */
/* ---------------------------------------------------------------------- */
void setup()
{
pinMode( redPin, OUTPUT );
pinMode( greenPin, OUTPUT );
pinMode( bluePin, OUTPUT );
}
/* ---------------------------------------------------------------------- */
/* loop() is predefined to be repeatedly called, if defined. This code */
/* sets each pin to a different analog value in [0 .. 255], and waits */
/* 1/2 second (500 milliseconds) between each change. */
/* ---------------------------------------------------------------------- */
void loop()
{
analogWrite( redPin, 30 ); delay( 500 ); /* dim red */
analogWrite( greenPin, 200 ); delay( 500 ); /* bright green (on dim red = yellow-green) */
analogWrite( bluePin, 40 ); delay( 500 ); /* dim blue (on above = washed out YG) */
analogWrite( redPin, 150 ); delay( 500 ); /* brighter red (to make brighter yellow) */
analogWrite( greenPin, 0 ); delay( 500 ); /* turn off green (for just slightly magenta) */
analogWrite( bluePin, 250 ); delay( 500 ); /* kick up blue to blue purple effect. */
}
I've been a programmer / designer now for what, 45 years? Has it been that long? Yep. Since age 14. At first, like most-everyone, I tended to follow the programming style of whatever examples (or the famous Kerningham & Richie 'C' book) were at hand. However, in the intervening years, I've taken to using both line-oriented, indent-oriented formatting AND column oriented form.
It makes it so much easier to read the code, to discern in this case what-all is being attempted. Especially the analogWrite()... delay() repetitions in loop().
I recommend this format. It definitely aids both debugging the code, but also explaining to others how it works. Moreover, it doesn't take very much overhead to do, while you're entering code. In fact, it saves a LOT of time in many cases, both from squashing bugs that are hard to see otherwise, mistakes that you miss, and because single-lines can be copy-pasted, yet do multiple things.
Hope all y'all agree.
But if not, write back!
GoatGuy (first post)
PS: now that I've reviewed how this site reformats things, I see that all multiple-space-characters are chewed up. DARN! Ah... learned to use the [ code ] block. It preserves spaces.
Last edited: