Physical Computing Assignment #1





// declare variables:
int switchPin1 = 2; // digital input pin for a switch
int switchPin2 = 6; // digital input pin for a 2nd switch
int switchPin3 = 7; // digital input pin for a 3rd switch
int yellowLedPin = 3; // digital output pin for an LED
int redLedPin = 4; // digital output pin for an LED
int greenLedPin = 5; // digital output pin for an LED
int switchState1 = 0; // the state of the switch
int switchState2 = 0; // the state of the switch
int switchState3 = 0; // the state of the switch
void setup() {
pinMode(switchPin1, INPUT); // set the switch pin to be an input
pinMode(switchPin2, INPUT); // set the switch pin to be an input
pinMode(switchPin3, INPUT); // set the switch pin to be an input
pinMode(yellowLedPin, OUTPUT); // set the yellow LED pin to be an output
pinMode(redLedPin, OUTPUT); // set the red LED pin to be an output
pinMode(greenLedPin, OUTPUT); // set the red LED pin to be an output
}
void loop() {
// read the switch input:
switchState1 = digitalRead(switchPin1);
switchState2 = digitalRead(switchPin2);
switchState3 = digitalRead(switchPin3);
// if the switch1 and/or switch2 are closed:
if (switchState1 == 1 && switchState2 == 1 && switchState3 == 1)
{
digitalWrite(yellowLedPin, HIGH); // turn on the yellow LED
digitalWrite(greenLedPin, HIGH); // turn on the yellow LED
digitalWrite(redLedPin, LOW); // turn off the red LED
delay(200);
digitalWrite(yellowLedPin, LOW); // turn on the yellow LED
digitalWrite(greenLedPin, LOW); // turn on the yellow LED
delay(200);
}
else
{
// if the switch is open:
digitalWrite(yellowLedPin, LOW); // turn off the yellow LED
digitalWrite(greenLedPin, LOW); // turn off the yellow LED
digitalWrite(redLedPin, HIGH); // turn on the red LED
}
}




