Yancha:
Hi Mee_n_Mac,
I would like to try it with Arduino.
A “Bunch” could be 5-10 LEDs per digital output (depends on the LED colour, right?).
You can drive 1 normal (20-30 mA) LED with each Arduino digital output pin. This is typically done by connecting a resistor in between the LED and the pin. The resistor sets the current through the LED. Any single output pin can supply or sink 40 mA max. There's also a max current spec, for all the pins summed together, that you need to stay under. I forget what that is, perhaps 200 mA total ? That may limit the number of LEDs that can be driven directly off the Arduino.
The color of the LED doesn’t affect how much current the LED will draw but does affect the voltage needed to achieve that current. So different colors will need different values for the resistor mentioned above. There are other ways to drive LEDs but let’s keep this simple for now. You may want to look at the wiring used here (I suspect you’ve already seen it though :mrgreen: ) …
http://oomlout.com/a/products/ardx/circ-02/
Yancha:
It would be much appreciated if you could help me with below code. It’s my first time using arduino, so I’m not sure if got it right. Thanks
I see a few problems right off the bat but I'll look at it in detail tomorrow. For now let me point those few out.
int ledPins[] = {2,3,4,5,6,7,8,9};
int buttonPin = 11;
void setup(){
for(int i = 0; i < 8; i ++){
pinMode(ledPins[i],OUTPUT);
pinMode(buttonPin, INPUT);
}
I believe your intent is to have pins 2 - 9 be the output pins used to drive the LEDs. You declare and then initialize them above. First, to save RAM usage, things that are constants and won’t ever change when the code runs, should be declared as constants. You do this by using the const instruction as part of the declaration. Second, and this is a small issue, it’ll work as written, the buttonPin initialization could be outside of the loop. It only needs to be done once. Lastly you were missing a }. So you get the following instead of the above …
const int ledPins[] = {2,3,4,5,6,7,8,9};
const int buttonPin = 11;
void setup(){
for(int i = 0; i < 8; i ++){
pinMode(ledPins[i],OUTPUT);
}
pinMode(buttonPin, INPUT);
}
I’ll also add that if pin 11 is an input used with a simple connect/no-connect switch (SP-NO or SP-NC) then it’s common practice to use the Arduino’s internal pull-up resistor. Depending on which version of the Arduino environment you’re using, there are different ways to initialize this pin to make this happen. Which Arduino (board and environment) are you using ?
Lastly (for now) … while you can use any name for the index in a for loop, using what you used below is confusing. Also when referencing the array ledPins[] you need to specify which pin is being used by using 's with the index into the array in the 's. So this …
for(int ledPins = 0; ledPins <= 7; ledPins++){
digitalWrite(ledPins, HIGH);
button_delay(delayTime, buttonPin);
}
… should be this (not to say that the result below necessarily does what you need/want). What the above would try to do is set pins 0 through 7 to a logic high. It might have compiled but it’s not what I think you intended.
for(int i= 0; i <= 7; i++){
digitalWrite(ledPins[i], HIGH);
button_delay(delayTime, buttonPin); // does this line want to be here ??????
}
Lastly you’ll note the code above is in “code boxes” and so retains the indentations you see in the Arduino editor and thus is easier to read. The pic below should explain how to use the code tags (you need to be using the “full” forum editor.
[/quote]