Help a newb?

I'm a newb and playing around with with my UNO. I'm using the "Getting Started with Arduino" book to get my feet wet. I've been playing with the PWM sketch that fades an LED, can someone explain in plain english how this part of the sketch works.

// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;

The sketch is working ,I would just like to understand the commands that I am typing in.....

When fadeAmount is + the LED will get brighter as brightness increases in value and when it gets to 255 the sign of fadeAmount goes negative then brightness will get smaller the LED gets dimmer when you get to 0 the sign of fadAmount goes positive and we again make the brightness of the led increase etc.

fadeAmount = -fadeAmount ; // inverts the sign

Thanks for the fast reply! I appreciate you taking the time to answer my question. I have a feeling this will be the first of many questions. Can anyone suggest a web site or source that explains C++ commands in plain english. I have Googled C++ programming but was overwhelmed with the number of sites to look at....
Thanks

comparing against 0 and 255 is dangerous unless the fadeAmount is 1 or -1, you could possibly improve it by making it a signed integer and then changing the operation to be something compare for less than 0 or greater than 255. of course, when you use the values, you'll need to use a floor and ceiling values to make sure only values between 0 and 255 are sent.. but this approach will allow you to change the rate in which the LED changes brightness (ie: from 1 to 2, 5 or 10)..

lamrick:
Thanks for the fast reply! I appreciate you taking the time to answer my question. I have a feeling this will be the first of many questions. Can anyone suggest a web site or source that explains C++ commands in plain english. I have Googled C++ programming but was overwhelmed with the number of sites to look at....
Thanks

the google search gives you a link to K&R C programming.. definitely worth buying it if you are going to use C/C++ a lot. start learning C, C++ is just a small extension and has the same foundations.

ardiri:

lamrick:
Thanks for the fast reply! I appreciate you taking the time to answer my question. I have a feeling this will be the first of many questions. Can anyone suggest a web site or source that explains C++ commands in plain english. I have Googled C++ programming but was overwhelmed with the number of sites to look at....
Thanks

https://www.youtube.com/playlist?list=PL76809ED684A081F3
Google

the google search gives you a link to K&R C programming.. definitely worth buying it if you are going to use C/C++ a lot. start learning C, C++ is just a small extension and has the same foundations.

I have downloaded a PDF on C programming , and will start studying it. Lots to learn. Thanks for the links!

LarryD:
Arduino - Home

http://www.amazon.ca/Arduino-Cookbook-Michael-Margolis/dp/1449313876

I have looked at the Arduino Reference on the home page before but forgot about it. Thanks for the reminder.