View on GitHub

oddgui

Lab 1

This is my first PhysComp lab. It involved the alternating the states of two LEDs.

Here is the code I used

More details on the lab could be found here

int switchButton = 2; // button
int pinYellow = 3; // Yellow LED
int pinGreen = 4; // Green LED
int switchIni = 0; // Initial state of switch

void setup(){
pinMode(switchButton, INPUT); //takes in switch signal
pinMode(pinYellow, OUTPUT); //yellow output
pinMode(pinGreen,OUTPUT); //green output
}

void loop(){
// read the switch
switchIni = digitalRead(switchButton);

if (switchIni == 1) {
// if the switch is closed:
digitalWrite(pinYellow, HIGH); // turn on the yellow LED
digitalWrite(pinGreen, LOW); // turn off the red LED
}
else {
//if the switch is open:
digitalWrite(pinYellow, LOW); // turn off the yellow LED
digitalWrite(pinGreen, HIGH); // turn on the red LED
}

}
In the wiring I initially had an issue with this. I did not realize I had put the red wire in the same rail as the blue. Thus I was getting a short

IMG_0093

</param></param></param></embed>

Physcomp – Lab 1 from Zeven Rodriguez on Vimeo.