Erin Beck’s Soft Switch

I created a switch that alternated lights. When on, the white LED would be lit and the red LED would be off. When turned off, the red LED would switch on and the white would switch off. I wanted to play with fabric and because I didn’t have any copper tape at home, I used regular tin foil.

Here is my code:

const int buttonPin = 2;
const int ledPin = 3; //LED white
const int ledPin2 = 4; // LED red
int buttonState = 0;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(buttonPin, INPUT);

void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// Alternate LED pins- red turns off, white turns on:
digitalWrite(ledPin, HIGH);
} else {
// Alternate LED pins-white turns off, red turns on:
digitalWrite(ledPin, LOW);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s