I am an absolute newbie to electronics and have a question. What is the best way to wure a two-wire bi-color to a diecimila? I want to drive the LED in both directions/colors and maybe pulse it to get a mixed color.
My first guess was to connect each pin to one port. But this will lead to connecting 5V to a digital out pin that is set to LOW (when setting the other pin to high). So that isn't a good idea, is it?
Is there another way connecting the led, avoiding other components than resistors and leds the realize this?
No you are not directly connecting a HIGH pin to a LOW pin, but you should include a resistor to limit the current.
As it doesn't matter if the resistor is before or after an LED, just put a resistor between one of the LED pins and the arduino. It cut one of the legs short, then soldered a short resistor on where the missing leg was, and cut the other resistor leg short to match the length of the remaining leg.
int green = 13; // +LED connected to digital pin 13
int red = 12; // -LED connected to digital pin 12
// The setup() method runs once, when the sketch starts
void setup() {
// initialize the digital pin as an output:
pinMode(green, OUTPUT);
pinMode(red, OUTPUT);
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()
{
digitalWrite(green, HIGH); // set the LED on
digitalWrite(red, LOW); // set the LED off
delay(1000); // wait for a second
digitalWrite(green, LOW); // set the LED off
digitalWrite(red, HIGH); // set the LED on
delay(1000); // wait for a second
}