Soft Switch Documentation
Materials:
Fabric pushbutton
Fabric pressure sensor
Code:
The code for the pushbutton is located in “File” –> “Examples” –> “Digital” –> “Button” in Arduino.
The code for the pressure sensor is a very simple variation of the AnalogInput example code:
/*
Liza Stark
Fabric Pressure Sensor
March 7, 2011
This is a variation of the AnalogInput code that can be found on the Arduino website.
http://arduino.cc/en/Tutorial/AnalogInput
*/
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 11; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
//pinMode(sensorPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
analogWrite(ledPin,sensorValue);
// write the value of the sensor to the ledPin using PWM
}
Fading LEDs and Tones
/*
Liza Stark
March 1, 2011
PWM Siren and Fading LEDs
*/
//Set and initialize variables for LED pins
int green = 10;
int red = 5;
int white = 6;
// Set and initialize variable for speaker
int speaker = 9;
//Set variable for fadeValue
int fadeValue;
void setup() {
// nothing happens in setup
}
void loop() {
// fade green up
for(fadeValue = 0 ; fadeValue <= 255; fadeValue +=1) {
// sets the value (range from 0 to 255):
analogWrite(green, fadeValue);
tone(speaker, 300 + fadeValue);
delay(30);
}
// fade green down
for(fadeValue = 255 ; fadeValue >= 0; fadeValue -=1) {
analogWrite(green, fadeValue);
Serial.println(fadeValue);
tone(speaker, fadeValue – 300);
delay(30); // delay to see fade
}
// fade red up
for(fadeValue = 0 ; fadeValue <= 255; fadeValue +=3) {
// sets the value (range from 0 to 255):
analogWrite(red, fadeValue);
Serial.println(fadeValue);
tone(speaker, 200 + fadeValue);
delay(30);
}
// fade red down
for(fadeValue = 255 ; fadeValue >= 0; fadeValue -=3) {
// sets the value (range from 0 to 255):
analogWrite(red, fadeValue);
Serial.println(fadeValue);
tone(speaker, fadeValue – 200);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
//fade white up
for(fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(white, fadeValue);
Serial.println(fadeValue);
tone(speaker, 100 + fadeValue);
delay(30);
}
// fade white down
for(fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(white, fadeValue);
Serial.println(fadeValue);
tone(speaker, fadeValue – 100);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}