Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
//Blinking and Fading
int led = 13;
int led2 = 11;
// This time the fade variable is a byte instead of an int.
byte fade;
// A big variable to keep track of the timer.
long timer;
// A variable to store when the last time something happened was.
long previousTimer;
// A variable for wether the LED is on or off.
int ledState = LOW;
void setup() {
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
Serial.begin(9600);
}
void loop() {
// An if statements checks if a condition is true. If it is, the code in the { } will run.
if ( timer - previousTimer >= 20 ) {
ledState = !ledState;
previousTimer = timer;
Serial.println(" ");
Serial.println("********* CHANGE STATE!!! ***********");
Serial.println(" ");
}
digitalWrite(led, ledState); // turn the LED on or off depending on the value of ledState.
analogWrite(led2, fade);
fade++;
timer++;
Serial.print("timer= ");
Serial.print(timer);
Serial.print("\t previousTimer= ") ;
Serial.print(previousTimer);
Serial.print("\t fade= ");
Serial.println(fade);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment