.. note:: Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts. **Why Join?** - **Expert Support**: Solve post-sale issues and technical challenges with help from our community and team. - **Learn & Share**: Exchange tips and tutorials to enhance your skills. - **Exclusive Previews**: Get early access to new product announcements and sneak peeks. - **Special Discounts**: Enjoy exclusive discounts on our newest products. - **Festive Promotions and Giveaways**: Take part in giveaways and holiday promotions. 👉 Ready to explore and create with us? Click [|link_sf_facebook|] and join today! .. _ar_bar_graph: 2.4 LED Bar Graph ================== Overview -------- In this lesson, you will learn something about LED Bar Graph. Generally, LED Bar Graph works as a battery level indicator, Audio equipment, industrial control panel. If we want, we can also find its other application. Components Required ------------------- .. image:: img/list_2.4.png * :ref:`cpn_mega2560` * :ref:`cpn_breadboard` * :ref:`cpn_wires` * :ref:`cpn_bar_graph` * :ref:`cpn_resistor` Fritzing Circuit ---------------- In this example, we use digital pins 2~11 to drive the LED Bar Graph. LED Bar Graph has ten separate LEDs inside and each LED has two pins. The left pins 1~10 of LED Bar Graph are connected with the digital pins 2~11 respectively; the right side pins 11~20 are separately extended to same side of these 220ohm resistors whose other sides are identically connected to GND. .. image:: img/image82.png Schematic Diagram ----------------- .. image:: img/image427.png Code ---- .. note:: * You can open the file ``2.4_ledBarGraph.ino`` under the path of ``sunfounder_vincent_kit_for_arduino\code\2.4_ledBarGraph`` directly. * Or copy this code into Arduino IDE. .. raw:: html Uploaded the codes to the Mega2560 board, you can see that the LEDs on the LED Bar Graph flash in sequence. Code Analysis ------------- The codes in setup() use the for loop to initialize pins 2~11 to output mode in turn. .. code-block:: arduino for(int i=2;i<=11;i++) { pinMode(i,OUTPUT); } The for loop is used in loop() to make the LED flash(turn on 0.5s, then turn off 0.5s) in sequence. .. code-block:: arduino for(int i=2;i<=11;i++) { digitalWrite(i,HIGH); delay(500); digitalWrite(i,LOW); delay(500); } Refer to **Part 1-1.2 Digital Write** for more details about controlling the LED by using digital pins. :ref:`ar_digital_write` Phenomenon Picture ------------------ .. image:: img/image84.jpeg