Chris’s Soft Switch

Description:

I use conductive fabric to create circuits connecting the three LED’S to arduino. I then use a switch to automate change from the green to red LED and vice versa. The transition from the green to red LED is accompanied by a short pause from the yellow LED in between. The transition from red to green LED is instant.

Video documenting how my project functions:

Source Code:

const int buttonPin = 3; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
const int yellowPin = 10;
int buttonState = 0; // variable for reading the pushbutton status
int state = 0;

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);//green led
pinMode(11, OUTPUT);//red led
pinMode(yellowPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is LOW, start red light cycle:
if (buttonState == LOW ) {
if(state == 0){
// turn RED on:
digitalWrite(11, LOW);
digitalWrite(yellowPin, HIGH);
delay(3000);
digitalWrite(yellowPin, LOW);
digitalWrite(ledPin, HIGH);

state = 1;
}

} else {
// start green light cycle:
digitalWrite(ledPin, LOW);
digitalWrite(11, HIGH);
state = 0;
}
}

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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