Skip to content

Instantly share code, notes, and snippets.

@arielchuri
Created September 6, 2013 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arielchuri/6469218 to your computer and use it in GitHub Desktop.
Save arielchuri/6469218 to your computer and use it in GitHub Desktop.
//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