# Light leds on this board one at a time

I am playing around with this Tinycircuits 16 LED board and I can figure out how to persistently light two LEDs at the same time. The page comes with an example that i can modify but I can only do 1 at a time

How do I light more than one LED at a time?

``````/*
TinyDuino Edge LED Demo

April 9 2014, by Ben Rose

This example code is in the public domain.

http://www.tiny-circuits.com

*/

void setup()
{
LedOn(0);//Pass a zero to turn all LEDs off
}

void loop()
{
for(int i=1;i<16;i++){
LedOn(i);
delay(20);
};
for(int i=16;i>1;i--){
LedOn(i);
delay(20);
};
}

void LedOn(int ledNum)
{
for(int i=5;i<10;i++){
pinMode(i, INPUT);
digitalWrite(i, LOW);
};
if(ledNum<1 || ledNum>16) return;
char highpin[16]={5,6,5,7,6,7,6,8,5,8,8,7,9,7,9,8};
char lowpin[16]= {6,5,7,5,7,6,8,6,8,5,7,8,7,9,8,9};
ledNum--;
digitalWrite(highpin[ledNum],HIGH);
digitalWrite(lowpin[ledNum],LOW);
pinMode(highpin[ledNum],OUTPUT);
pinMode(lowpin[ledNum],OUTPUT);
}
``````
• What is your question?
– user15297
Dec 14 '15 at 21:14
• Sorry I copied over the question with the paste of the code. Dec 14 '15 at 21:16
• Oh, okay. I get it. I'll undo the downvote.
– user15297
Dec 14 '15 at 21:16

This is your circuit.

I think you can take it from here by looking at the diagram, but please note that e.g. 1 0 0 0 0 will light up 3 and 1, so be careful.

To show more than one, turn on multiple LEDs in rapid succession. It will give the effect that more than one are on. This is known as multiplexing.

Update:

After Googling around, I understood it better. I also wrote this code.

``````int IO1 = 50;
int IO2 = 48;
int IO3 = 46;
int IO4 = 44;
int IO5 = 41;
int del = 1000;

void setup() {

pinMode(IO1, INPUT);
pinMode(IO2, INPUT);
pinMode(IO3, INPUT);
pinMode(IO4, INPUT);
pinMode(IO5, INPUT);
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
displayLED(1);
delay(del);
displayLED(2);
delay(del);
displayLED(3);
delay(del);
displayLED(4);
delay(del);
displayLED(5);
delay(del);
displayLED(6);
delay(del);
displayLED(7);
delay(del);
displayLED(8);
delay(del);
displayLED(9);
delay(del);
displayLED(10);
delay(del);
displayLED(11);
delay(del);
displayLED(12);
delay(del);
displayLED(13);
delay(del);
displayLED(14);
delay(del);
displayLED(15);
delay(del);
displayLED(16);
delay(del);// light up LEDS 1, 2 and 3.
}

void displayLED(int a){
clear();
if (a == 1){o(1); o(2); h(1); l(2); Serial.println('1');}
if (a == 2){o(1); o(2); l(1); h(2); Serial.println('2');}
if (a == 3){o(1); o(3); h(1); l(3); Serial.println('3');}
if (a == 4){o(1); o(3); l(1); h(3); Serial.println('4');}
if (a == 5){o(2); o(3); h(2); l(3); Serial.println('5');}
if (a == 6){o(2); o(3); l(2); h(3); Serial.println('6');}
if (a == 7){o(2); o(4); h(2); l(4); Serial.println('7');}
if (a == 8){o(2); o(4); l(2); h(4); Serial.println('8');}
if (a == 9){o(1); o(4); h(1); l(4); Serial.println('9');}
if (a == 10){o(1); o(4); l(1); h(4); Serial.println(10);}
if (a == 11){o(3); o(4); l(3); h(4); Serial.println(11);}
if (a == 12){o(3); o(4); h(3); l(4); Serial.println(a);}
if (a == 13){o(3); o(5); l(3); h(5); Serial.println(a);}
if (a == 14){o(3); o(5); h(3); l(5); Serial.println(a);}
if (a == 15){o(4); o(5); l(4); h(5); Serial.println(a);}
if (a == 16){o(4); o(5); h(4); l(5); Serial.println(a);}

}

void clear(){pinMode(IO1, INPUT);
pinMode(IO2, INPUT);
pinMode(IO3, INPUT);
pinMode(IO4, INPUT);
pinMode(IO5, INPUT);}

void o(int o){
if (o == 1){pinMode(IO1, OUTPUT);}
if (o == 2){pinMode(IO2, OUTPUT);}
if (o == 3){pinMode(IO3, OUTPUT);}
if (o == 4){pinMode(IO4, OUTPUT);}
if (o == 5){pinMode(IO5, OUTPUT);}
}

void h(int l){
if (l == 1){digitalWrite(IO1, HIGH);}
if (l == 2){digitalWrite(IO2, HIGH);}
if (l == 3){digitalWrite(IO3, HIGH);}
if (l == 4){digitalWrite(IO4, HIGH);}
if (l == 5){digitalWrite(IO5, HIGH);}
}

void l(int h){
if (h == 1){digitalWrite(IO1, LOW);}
if (h == 2){digitalWrite(IO2, LOW);}
if (h == 3){digitalWrite(IO3, LOW);}
if (h == 4){digitalWrite(IO4, LOW);}
if (h == 5){digitalWrite(IO5, LOW);}
}
``````
• I probably couldn't take it any further without an example of code. Dec 16 '15 at 14:52
• @Crash893 Okay, I'll edit.
– user15297
Dec 17 '15 at 18:05
• @Crash893 Did the code work?
– user15297
Dec 18 '15 at 16:29
• i left the device at work ill try when i get back after vacation Dec 20 '15 at 22:42

That is an interesting challenge. You should include the circuit diagram for this. It really helps understand the code.

.

There is excellent information on this technique to reduce number of pins here.

Cheers!