Seg 2: Arduino controls many LEDs

2.4 Experimental platform

According to Figure 2-2, we start to set up the experimental platform, as shown Figure 2-2. Oh, my god, there are so much LEDs, dupont lines, and resistors, that we are confused by the complex connection. But can we rightly connect the electrical elements? In fact, it is not difficult if we can find a technique. Then, it will be very simple to set up our such experiment.

  1. As for one LED, the long les is located left side for positive, and the other is located right side for negative. if all of these LEDs are connected by this method, it is not a problem.
  2. One end of dupont line is connected to negative polarity (by the equal voltage for each column in the brandboard). Another end is connected to GND. All of these ends are connected the same line in the narrow band (the equal voltage for each row in the narrow band).
  3. The current-limited resistors are connected to the polarities of LEDs. Similarly, they are located randomly in the same column. But for the good-looking, they had better be connected unifiedly the different columns at the same line in the brandband. It will look like neat, as shown in Figure 2-2.
  4. One end is connected to resistor at the same column, and the other is connected to the pins on the Arduino board, as shown in Figure 2-2.

OK, when you have a few techniques to connect these electronic elements on the Arduino board, you may finish this connection of this experiment successfully at a time. The circuit is not complex, but it needs your carefulness.

Wow, when we insert USB line into computer and Arduino board, the LED is blinking repeatedly at pin 8 on the Arduino board. But other LEDs are honest, and not blinking. Why? Yes, maybe, you have got it. Do you remember the previous experiment? We let LED blink located at pin 8 on the Arduino board. When the code has been burnt into the Arduino board, it can be saved in the board forever. It does not disappear with the power off of Arduino board. If we repower on the Arduino board, the LED will blink at pin 8. But, if we burn a new program into the Arduino board, the board will execute the new code.


Figure 2-3 Start to write the letter V


Figure 2-4 The letter V

2.5 Solution for code

On the basis of the last experiment on the Arduino IDE, we can give out the code in this experiment, which is exhibited in Program 2.

01 //Program 2: Arduino controls many LEDs
02 //define 9 pins for LEDs
03 int led4 = 4;
04 int led5 = 5;
05 int led6 = 6;
06 int led7 = 7;
07 int led8 = 8;
08 int led9 = 9;
09 int led10 = 10;
10 int led11 = 11;
11 int led12 = 12;
12
13 //initialize the 9 pins as OUTPUT
14 void setup()
15 {
16    for(int i=4;i<=12;i++)//define 4-12 as OUTPUT
17    pinMode(i,OUTPUT);//set i as OUTPUT
18 }
19
20 void loop()
21 {
22  mode();//display of 9 LEDs
23
24 }
25 //subfunction for mode()
26 void mode()
27 {
28  unsigned char j;
29  //let 4-12 LEDs blink one by one
30  for(j=12;j>=4;j–)
31  {
32    digitalWrite(j,HIGH);
33    delay(500);
34  }
35  //let 4-12 LEDs go out
36  for(j=12;j>=4;j–)
37  {
38    digitalWrite(j,LOW);
39  //delay(500);
40  }
41  //let 4-12 LEDs bright
42  for(j=4;j<=12;j++)
43  {
44    digitalWrite(j,HIGH);
45  }
46 }


 2.6 Key points

1) Be familiar with the polarity of LED and the features of breadboard.

2) After finishing a experiment, we should summarize some experiences from the process of experiment.

3) Arduino can realize your idea. Do it yourself.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>