| e-textile construction kit Arduino library jump to a section: controlling tabs: controlling RGB LEDs:
color(red_amount, green_amount, blue_amount) simpleColor(color_number) setGradient() cycleColors() controlling speakers:
alarm(tab_speaker_is_sewn_to) sensorSound(tab_speaker_is_sewn_to, sensor_value) controlling tabs The macros described in this section enable you to control each tab on your fabric patch. tabxInput()
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(); }
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); }
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); }
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); }
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()
Example - cycle through the colors of an RGB LED forever: void setup() { initializeRGB(); //initialize the RGB LED } void loop() { cycleColors(); }
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); }
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); }
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); }
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)
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); }
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); }
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). |