Say you want to create 5 L.E.D.'s doing a simple chase but you want maybe 2 or 3 on at the same time. I could just stick 2-3 on a single pin I guess? Is there a limit to how many lights you can put on one pin?
Then you write your sketch to have 2 or 3 on at a time.
For example, say you send this array contents to 5 io pins, where 0 if off and 1 is on:
byte displayArray [] = {
0b00000000,
0b00000001,
0b00000011,
0b00000110,
0b00001100,
0b00011000,
0b00001100,
0b00000110,
0b00000011,
0b00000001,
0b00000000,
};
[code]
Make sense? Fix up the pattern however you'd like, then send it to outputs every 1/4 second or so.
If you used D8-D12 for example, you could just the array to portB:
[code]
void loop(){
for (x=0; x<11; x=x+11){
PORTB = displayArray[x];
delay (250); // dumb 1/4 second delay, there are smarter ways to do this to allow button reads and stuff
}
}
How many 3 volt L.E.D.s can a micro or nano board have do you think. I was going to pulse modulate (create 22 glowing L.E.D.'s) but I'm wondering if the nano or Micro can handle that many lights. They all dim at the same time. I guess I have 7 PWM pins on the micro so I would have to have 3-4 on each PWM Pin. Or would I need a transistor?
Nano's '328P uses 2 VCC and 2 Gnd pins, each capable of 200mA; you could switch 300mA via IO pins safely per the datasheet. There are some limits on how much each port can control, for 300mA total, see section 31 or 32 of the datasheet for full details.
20 IO pins = 20 LEDs at 15mA each with a current limit resistor for each.
40 LEDs at 7.5mA each, each with a current limit resistor, 2 per IO pin.
If all are to do the same thing all the time, then using a transistor to sink all the current makes more sense. Can even use a higher voltage source and share the current among LEDs in series (say 4 from a 12V source).
328P has 6 hardware PWM pins, or you can do software PWM for more pins.
Thanks CrossRoads for you help. Very appreciated. I'm interested in buying your book. Have it in my Wish List on Amazon. Is there a list of projects the book covers anywhere?
How can i get this to run once and stop. Its says NoLoop but it keeps looping.
int ledPins[] = {2,3,4,5,6,};
void setup()
{
int index;
for(index = 0; index <= 6; index++)
{
pinMode(ledPins[index],OUTPUT);
}
}
void loop()
{
oneAfterAnotherNoLoop(); // Light up all the LEDs in turn
}
void oneAfterAnotherNoLoop()
{
// turn all the LEDs on:
digitalWrite(ledPins[0], HIGH); //Turns on LED #1 (pin 2)
delay(100);
digitalWrite(ledPins[0], LOW); //Turns off LED #1 (pin 2)
delay(100);
digitalWrite(ledPins[1], HIGH); //Turns on LED #2 (pin 3)
delay(100);
digitalWrite(ledPins[1], LOW); //Turns off LED #2 (pin 3)
delay(100);
digitalWrite(ledPins[2], HIGH); //Turns on LED #3 (pin 4)
delay(100);
digitalWrite(ledPins[2], LOW); //Turn off LED #3 (pin 4)
delay(100);
digitalWrite(ledPins[3], HIGH); //Turns on LED #4 (pin 5)
delay(100);
digitalWrite(ledPins[3], LOW); //Turn off LED #4 (pin 5)
delay(100);
digitalWrite(ledPins[4], HIGH); //Turns on LED #5 (pin 6)
delay(100);
digitalWrite(ledPins[4], LOW); //Turn off LED #5 (pin 6)
delay(100);
The way loop() and setup() are used is - setup() gets called once, then loop() gets called continually (internally, it looks like setup(); while (1) {loop();} )
I did that. And now it does run once and stops but the light are very very dim>
CODE:
int ledPins[] = {2,3,4,5,6,};
void setup()
{
int index;
oneAfterAnotherNoLoop();
for(index = 0; index <= 6; index++)
{
pinMode(ledPins[index],OUTPUT);
}
}
void loop()
{
}
void oneAfterAnotherNoLoop()
{
// turn all the LEDs on:
digitalWrite(ledPins[0], HIGH); //Turns on LED #1 (pin 2)
delay(100);
digitalWrite(ledPins[0], LOW); //Turns off LED #1 (pin 2)
delay(100);
digitalWrite(ledPins[1], HIGH); //Turns on LED #2 (pin 3)
delay(100);
digitalWrite(ledPins[1], LOW); //Turns off LED #2 (pin 3)
delay(100);
digitalWrite(ledPins[2], HIGH); //Turns on LED #3 (pin 4)
delay(100);
digitalWrite(ledPins[2], LOW); //Turn off LED #3 (pin 4)
delay(100);
digitalWrite(ledPins[3], HIGH); //Turns on LED #4 (pin 5)
delay(100);
digitalWrite(ledPins[3], LOW); //Turn off LED #4 (pin 5)
delay(100);
digitalWrite(ledPins[4], HIGH); //Turns on LED #5 (pin 6)
delay(100);
digitalWrite(ledPins[4], LOW); //Turn off LED #5 (pin 6)
delay(100);