I wrote a very simple blink program which just flashes 3 sets of 2 LEDs at different intervals. I have each set of 2 LEDs wired to their own resistor and then to the 5v rail, then the negative leg I have tied together for each set and then bridged to a pin on the arduino. The function blinks the first leds twice as it should but then leave it on and goes to the next. The first set never really turns off except for when it does its "blink" routine but stays on during the other 2 routines The second set of LEDs do the same thing, but the third set stay off when they are supposed to.. Hopefully this will make more sense when you see the program which I have attached:
// Pins 3, 5 and 6 will be used for LEDs.
// give them a name:
int RedLED = 3;
int BlueLED = 5;
int GreenLED = 6;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pins as an output.
pinMode(RedLED, OUTPUT);
pinMode(BlueLED, OUTPUT);
pinMode(GreenLED, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(GreenLED, HIGH);
delay(50);
digitalWrite(GreenLED, LOW);
delay(50);
digitalWrite(GreenLED, HIGH);
delay(50);
digitalWrite(GreenLED, LOW);
delay(50);
digitalWrite(RedLED, HIGH);
delay(50);
digitalWrite(RedLED, LOW);
delay(50);
digitalWrite(RedLED, HIGH);
delay(50);
digitalWrite(RedLED, LOW);
delay(50);
digitalWrite(BlueLED, HIGH);
delay(50);
digitalWrite(BlueLED, LOW);
delay(50);
digitalWrite(BlueLED, HIGH);
delay(50);
digitalWrite(BlueLED, LOW);
delay(50);
digitalWrite(BlueLED, HIGH);
delay(50);
digitalWrite(BlueLED, LOW);
delay(50);
digitalWrite(BlueLED, HIGH);
delay(50);
digitalWrite(BlueLED, LOW);
delay(50);
digitalWrite(RedLED, HIGH);
delay(50);
digitalWrite(RedLED, LOW);
delay(50);
digitalWrite(RedLED, HIGH);
delay(50);
digitalWrite(RedLED, LOW);
delay(50);
digitalWrite(GreenLED, HIGH);
delay(50);
digitalWrite(GreenLED, LOW);
delay(50);
digitalWrite(GreenLED, HIGH);
delay(50);
digitalWrite(GreenLED, LOW);
delay(50);
}
Nope...didn't realize that. That is exactly what I wanted it to do once I switched the highs and lows. Will those pins put out either negative or positive? Can I inversely wire this so that HIGH would turn the lights on?
Yes. I did change the code and it works as expected now. Just trying to learn as I go. Working on this project with my son and want to be able to teach him what I learn as well and don't want to lead him astray. Thanks for the help guys, I really appreciate it.
But then you wouldn't have known that your post wasn't clear. You said different intervals, but the code says the same interval.
You said "the first set of LEDs" without saying what pin they are attached to, or even describing well what the problem is. "never really turns off" could mean a host of things. Since there is no PWM involved, an OUTPUT pin is either on or off. There is no "not really off" setting.
electricd7:
Will those pins put out either negative or positive? Can I inversely wire this so that HIGH would turn the lights on?
When HIGH an Arduino pin will supply current to an LED and resistor in series, if the combination is grounded. You have wired it so that when LOW, the Arduino pin "sinks" current to ground, from the power supply through the LED/resistor.