9/17/2009

#_1a Blinking LED Switch

This is my Arduino. Ground and power (5V) are hooked up.













This is my setup consisting of the Arduino microcontroller, a breadboard, yellow and red LED, 10k resistor (switch) and two 220 resistors (LEDs) and wires. I used two wires as switch, which I connected by using a screwdriver.













These are the blinking lights.









Video of the final product.


The code used was the basic code provided on the ITP PComp Wiki, i.e.:
// declare variables:
int switchPin = 2;      //  digital input pin for a switch
int yellowLedPin = 3;   //  digital output pin for an LED
int redLedPin = 4;      //  digital output pin for an LED
int switchState = 0;    // the state of the switch

void setup() {
pinMode(switchPin, 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
}

void loop() {
// read the switch input:
switchState = digitalRead(switchPin);

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

}


Source: http://itp.nyu.edu/physcomp/Labs/DigitalInOut

Keine Kommentare:

Kommentar veröffentlichen