This example is for Wiring version 0027+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.
Increment Decrement. by BARRAGAN
Writing "a++" is equivalent to "a = a + 1". Writing "a--" is equivalent to "a = a - 1".
Writing "a++" is equivalent to "a = a + 1". Writing "a--" is equivalent to "a = a - 1".
int current = 0; // variable the keeps which light must be turn on next void setup() { for(int i = 0; i < 8; i++) { // set pins 0-7 as outputs pinMode(i, OUTPUT); } } void loop() { turn_all_off(); // turns all LEDs off digitalWrite(current, HIGH); // set the current light ON delay(200); // wait for 200ms current++; // increment current LED if(current > 7) { // range check, if last LED goes back to LED 0 current = 0; } } void turn_all_off() { // function to turn off all the LEDs for(int i = 0; i < 8; i++) { // connected to digital pins 0-7 digitalWrite(i, LOW); } }