e-textile construction kit Arduino library

jump to a section:

controlling tabs: controlling RGB LEDs:
controlling speakers:


controlling tabs

The macros described in this section enable you to control each tab on your fabric patch.

tabxInput()
    Declares a tab to be an input. Use in the setup function, when you want tab to read input from a switch or other input device.
    Example - LED is on while switch attached to tab2 is pressed:

    void setup() {
        tab2Input();                 //set tab2 as an input for switch
    }

    void loop() {
        while (tab2IsLow())
        {
            LEDOn();
        }
        LEDOff();
    }
tabxOutput()
    Declares a tab to be an output. Use in the setup function, when you want tab to control an LED, speaker, motor or other output device.
    Example - LED attached to tab2 blinks on for 1 second and then off for 1 second forever:

    void setup() {
        tab2Output();                 //set tab2 as an output for LED
    }

    void loop() {
        tab2High();
        delay(1000);
        tab2Low();
        delay(1000);
    }
tabxOn() and tabxOff()
    Sets an output tab to either +5 volts or 0 volts/ground. Use in the loop function to control an LED, speaker, motor or other output device.
    Example - LED attached to tab2 blinks on for 1 second and then off for 1 second forever:

    void setup() {
        tab2Output();
    }

    void loop() {
        tab2On();                //set tab2 to +5 volts (turn LED on)
        delay(1000);
        tab2Off();                 //set tab2 to 0 volts (turn LED off)
        delay(1000);
    }
tabxHigh() and tabxLow()
    Identical to tabxOn() and tabxOff(). Sets an output tab to either +5 volts or 0 volts/ground. Use in the loop function to control an LED, speaker, motor or other output device.
    Example - LED attached to tab2 blinks on for 1 second and then off for 1 second forever:

    void setup() {
        tab2Output();
    }

    void loop() {
        tab2High();                //set tab2 to +5 volts (turn LED on)
        delay(1000);
        tab2Low();                 //set tab2 to 0 volts (turn LED off)
        delay(1000);
    }
tabxIsLow()
    Reads input from a tab. Use in the loop function. Returns TRUE if switch attached to tab is pressed.
    Example - LED is on while switch attached to tab2 is pressed:

    void setup() {
        tab2Input(); }

    void loop() {
        while (tab2IsLow())        //while loop will execute when switch attached to tab2 is pressed
        {
            LEDOn();
        }
        LEDOff();
    }

controlling RGB LEDs

These functions enable you to control RGB LEDs in a few different ways. RGB LEDs must always be attached to pins 9, 10 and 11 to function properly. Attach the green lead of the RGB LED to pin 9, the blue lead to pin 10 and the red lead to pin 11.

initializeRGB()
    This function must be called in the setup function, before any other RGB LED functions can be used.
    Example - cycle through the colors of an RGB LED forever:

    void setup() {
        initializeRGB();        //initialize the RGB LED
    }

    void loop() {
        cycleColors();
    }
color(red_amount, green_amount, blue_amount)
    This function provides standard R G B control for the LED. Use in the loop function. It accepts three arguments: a number from 0-255 for the amount of red, a number from 0-255 for the amount of green and a number from 0-255 for the amount of blue. See a web color mixing chart to get a feel for RGB color mixing.
    Example - turn red then green, then blue then off for 1 second each, forever:

    void setup() {
        initializeRGB();
    }

    void loop() {
        color(255,0,0);        //turn RGB LED red
        delay(1000);
        color(0,255,0);        //turn RGB LED green

        delay(1000);
        color(0,0,255);        //turn RGB LED blue
        delay(1000);
        color(0,0,0);            //turn RGB LED off
        delay(1000);
    }
simpleColor(color_number)
    This function takes a single number from 0-1023 as input and translates that number into a color from blue (0) to red (1023). Use this function in the loop function to easily display sensor data in an RGB LED. See also the setGradient() function and the sensorSound() function for a similar function for sound.
    Example - turn blue then green then red for 1 second each, forever:

    void setup() {
        initializeRGB();
    }

    void loop() {
        simpleColor(0);              //turn RGB LED blue
        delay(1000);
        simpleColor(512);         //turn RGB LED green

        delay(1000); 
        simpleColor(1023);        //turn RGB LED red
        delay(1000);
    }
setGradient(low_point, medium_point, high_point)
    Use in the setup function. This function takes three numbers from 0-1023 as input. These numbers define a range and mid-point over which the simpleColor() function will range. After calling this function, anything below the low point will be displayed as blue, anything above the high point will be displayed as red and the midpoint will be displayed as green. Colors will gradate from blue to green to red according to the slopes defined by the set_gradient arguments. By default, the simple color function ranges from 0-1023 with a midpoint of 512.

    This function is useful for tuning RGB LED output to various sensors. For example if you want your LED to display slight changes in temperature, right around room temperature, you can use this function to tune the simpleColor() function to do so.
    Example - set the gradient to have a low point of 100, a mid-point of 500 and a high point of 800. Then display sensor data in an RGB LED:


    int sensor_value;
    int sensor_tab = a0;

    void setup() {
        initializeRGB();
        setGradient(100,500,800);         //set gradient
    }

    void loop() {
        sensor_value = analogRead(sensor_tab);
        simpleColor(sensor_value);
    }
cycleColors()
    Use in the loop function. This function will gradually cycle through all the colors an RGB LED is capable of displaying.
    Example - repeatedly cycle through all RGB LED colors:

    void setup() {
        initializeRGB();
    }

    void loop() {
        cycleColors();         //cycle through the RGB LED colors
    }

controlling sound

These functions allows you to use small speakers to produce sound.

beep(tab_speaker_is_sewn_to)
    Use in the loop function. This function allows you to produce a beeping sound. Takes a number from 0-11 as an input indicating which tab the speaker is sewn to.
    Example - produce a beep from a speaker attached to tab2 every two seconds:

    void setup() {
        tab2Output();
    }

    void loop() {
        beep(2);        //beep a speaker attached to tab2
        delay(2000);
    }

alarm(tab_speaker_is_sewn_to)
    Use in the loop function. This function produces an alarm sound. Takes a number from 0-11 as an input indicating which tab the speaker is sewn to.
    Example - sound an alarm from a speaker attached to tab2 every second:

    void setup() {
        tab2Output();
    }

    void loop() {
        alarm(2);        //sound an alarm from a speaker attached to tab2
        delay(1000);
    }

sensorSound(tab_speaker_is_sewn_to, sensor_value)
    Use in the loop function. This function produces a sound whose pitch varies according to "sensor_value". "tab_speaker_is_sewn_to" should be a number from 0-11 indicating which tab the speaker is sewn to. "sensor_value" should be a number from 0-1023. The higher the "sensor_value" number the lower the pitch of the sound. Use this function
    in the loop function to easily translate sensor data into sound.
    Example - produce sounds from a speaker attached to tab2:

    void setup() {
        tab2Output();
    }

    void loop() {
        sensorSound(2,100);        //produce a high pitched sound from a speaker attached to tab2
        delay(1000);
        sensorSound(2,1000);       //produce a low pitched sound from a speaker attached to tab2
        delay(1000);
    }






This material is based upon work supported by the National Science Foundation under Grant No. 0326054.

Any opinions, findings and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation (NSF).