IncrementDecrement \ Learning \ Wiring ALPHA 1.0
Author: Hernando Barragán
Description: Wiring is an electronic sketchbook and hardware electronics for developing ideas. It is a context for learning fundamentals of computer programming and prototyping with electronics within the context of the electronic arts.
Keywords: Wiring, Processing, Interactive Media, Electronic Arts, Programming, C, C++, Hernando Barragán

Search wiring.org.co:

This example is for Wiring version 0023+. 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".

    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);
      }
    }