Skip to content

Instantly share code, notes, and snippets.

@arielchuri
Last active December 22, 2015 05:58
Show Gist options
  • Save arielchuri/6427448 to your computer and use it in GitHub Desktop.
Save arielchuri/6427448 to your computer and use it in GitHub Desktop.
Increment variable up and down and print it.
//Variables go first
int fred = 0;
int fredDir= 0; //0 means fred is going up. 1 for down
//setup runs once
void setup() {
}
//draw happens over and over
void draw() {
if (fredDir == 0) { //this code only happens if fred is waxing
fred = fred + 1; //add one to fred
if (fred == 256 ) { // if fred gets to 256 change fredDir
fredDir = 1;
}
}
if (fredDir == 1) { //this code only happens if fred is waning
fred = fred - 1;
if (fred == 0) {
fredDir = 0;
}
}
println(fred);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment