Sunday, June 20, 2010

lilypad_forcesensor_led


















/* this program will light up an led attached to pin 13
of the lilypad when the force sensor is depressed.
modified from this excellent resource:
http://web.media.mit.edu/~leah/LilyPad/05_switches.html
Prof. Emily Puthoff | 2010
*/

int ledPin = 13;      // LED is connected to digital pin 13. Pin 13 on lilypad has a built-in resistor for led, so no need to build into the circuit
int switchPin = 2;     // switch connected to digital pin 2
int switchValue;     // a variable to keep track of when switch is pressed

void setup()    
{    
  pinMode(ledPin, OUTPUT);     // sets the ledPin to be an output
  pinMode(switchPin, INPUT);     // sets the switchPin to be an input
  digitalWrite(switchPin, HIGH); // sets the default (unpressed) state of switchPin to HIGH
}    

void loop()     // run over and over again
{    
  switchValue = digitalRead(switchPin);     // check to see if the switch is pressed
  if (switchValue == LOW) {     // if the switch is pressed then,
    digitalWrite(ledPin, HIGH);     // turn the LED on
  }    
  else {     // otherwise,
    digitalWrite(ledPin, LOW);     // turn the LED off
  }    
}    

1 comment:

  1. I found a mistake of this program
    you need
    */
    to end the comment.

    ReplyDelete