Created
September 6, 2013 20:07
-
-
Save arielchuri/6469218 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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