# LED Binary Counter

## Penjelasan Proyek

Pada proyek ini, kita akan membuat binary counter dengan 8 buah LED.

## Daftar Komponen

Komponen yang diperlukan yaitu sebagai berikut:

* Board ESP32
* Breadboard
* LED 5 mm sebanyak 8 buah
* Resistor 330 Ω sebanyak 8 buah

## Rangkaian

Rangkaian yang dibuat yaitu sebagai berikut. LED dirangkai dengan konfigurasi rangkaian active-high pada pin-pin GPIO. Pin-pin GPIO yang digunakan dari kiri ke kanan yaitu 0, 4, 16, 17, 3, 1, 22, 23.

<figure><img src="/files/kwJ5AYpUtapz9dR6SJvP" alt="" width="441"><figcaption></figcaption></figure>

## Kode Program

Kode program yang dibuat yaitu sebagai berikut. Program akan menyalakan LED sesuai dengan nilai variable `i` dari perintah `for` loop. Delay antara nilai yaitu 100 ms. Fungsi `displayBinary()` digunakan untuk menyalakan 8 buah LED sesuai angka yang dimasukan.

{% code title="led\_binary\_counter.ino" lineNumbers="true" %}

````arduino
// uint8_t pin[8] = {23, 22, 1, 3, 17, 16, 4, 0}; // Right MSB
uint8_t pin[8] = {0, 4, 16, 17, 3, 1, 22, 23}; // Left MSB

void setup()
{
  for (int i = 0; i <= 7; i++)
    pinMode(pin[i], OUTPUT);
}

void loop() 
{
  for (byte i = 0; i <= 255; i++)
  {
    displayBinary(i);
    delay(100);
  }
}

void displayBinary(byte numToShow)
{
  for (int i = 0; i <= 7; i++)
  {
    if (bitRead(numToShow, i) == 1)
      digitalWrite(pin[i], HIGH);
    else
      digitalWrite(pin[i], LOW);
  }
}

```
````

{% endcode %}

{% embed url="<https://github.com/weenslab/proyek_arduino/blob/main/led/led_binary_counter/led_binary_counter.ino>" %}

## Hasil

Hasil dari proyek ini yaitu pada gambar berikut ini.

<figure><img src="/files/hlqLvfOJUBdJdoexX8Qb" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://weenslab.gitbook.io/pages/proyek-arduino/kumpulan-proyek/led-binary-counter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
