I am a noob with C/C++, But i have done some Perl in my day and can understand a lot of the programing languages out there.
This is my first code I ever made for an Arduino Leonardo that verified with no error's, but will it work the way I think it should?
It should be another way of doing http://bildr.org/2012/03/rfp30n06le-arduino/
Using PWM to fade a pin from 0 to 255 and 255 to 0.
I don't want to upload it and it brake my new toy.
//////////////////////////////////////////////////////////////////
//By: S_Flex
//Date: 11/09/2012
//Fade PWM output
//////////////////////////////////////////////////////////////////
#define fadePin3 3
#define DelayTime 15
int ThisLoop = 0; // current loop style 0 for ++ and 255 for --
int NextLoop = 255;
void setup(){
pinMode(fadePin3, OUTPUT);
}
void loop(){
// Fade pin loop
for(int i = ThisLoop; i<NextLoop;){
if (ThisLoop == 0) i++; // Will this work? Or should I do if & else?
if (ThisLoop == 255) i--;
analogWrite(fadePin3, i);
delay(DelayTime);
}
// Set next loop
if(ThisLoop == 0) {
ThisLoop = 255;
NextLoop = 0;
}
else if (ThisLoop == 255) {
ThisLoop = 0;
NextLoop = 255;
}
}