---
title: "Comment by Christian Foucher on \"ESP32 Standard Library Embedded Rust: GPIO Control\" | Hashnode"
description: "I think you should use an array instead of declaring 10 variables (one variable by pin!). Then you will be able to iterate the array with a for loop. // Configu"
url: "https://hashnode.com/posts/esp32-standard-library-embedded-rust-gpio-control/64afe421c3220ca4300ee7a2/comment/64b94706a884f3de56a26afd"
---

[Discussion](https://hashnode.com/posts/esp32-standard-library-embedded-rust-gpio-control/64afe421c3220ca4300ee7a2)

Comment [ESP32 Standard Library Embedded Rust: GPIO Control](https://hashnode.com/posts/esp32-standard-library-embedded-rust-gpio-control/64afe421c3220ca4300ee7a2)

[Christian Foucher](https://hashnode.com/@Valda60)

[Jul 20, 2023](https://hashnode.com/posts/esp32-standard-library-embedded-rust-gpio-control/64afe421c3220ca4300ee7a2/comment/64b94706a884f3de56a26afd)

I think you should use an array instead of declaring 10 variables (one variable by pin!). Then you will be able to iterate the array with a for loop.

// Configure all LED pins to digital outputs let mut leds = \[ PinDriver::output(dp.pins.gpio1.downgrade\_output()).unwrap(), PinDriver::output(dp.pins.gpio10.downgrade\_output()).unwrap(), PinDriver::output(dp.pins.gpio19.downgrade\_output()).unwrap(), PinDriver::output(dp.pins.gpio18.downgrade\_output()).unwrap(), PinDriver::output(dp.pins.gpio4.downgrade\_output()).unwrap(), PinDriver::output(dp.pins.gpio5.downgrade\_output()).unwrap(), PinDriver::output(dp.pins.gpio6.downgrade\_output()).unwrap(), PinDriver::output(dp.pins.gpio7.downgrade\_output()).unwrap(), PinDriver::output(dp.pins.gpio8.downgrade\_output()).unwrap(), PinDriver::output(dp.pins.gpio9.downgrade\_output()).unwrap(), \];

// Put the following code in the loop for mut led in &mut leds { // LED i led.set\_high().unwrap(); blinkdelay = button\_pressed(&button, &blinkdelay); FreeRtos::delay\_ms(blinkdelay); led.set\_low().unwrap(); FreeRtos::delay\_ms(100\_u32); }

// I have tested the result on wokwi

[Omar Hiari](https://hashnode.com/@omarhiari)

[Jul 20, 2023](https://hashnode.com/posts/esp32-standard-library-embedded-rust-gpio-control/64afe421c3220ca4300ee7a2/comment/64b94706a884f3de56a26afd#reply-64b9a4c1af9957de874117ab)

Thanks for the tip [Christian Foucher](https://hashnode.com/@Valda60)! You are absolutely correct. I actually had the same thought when creating the application, however, my issue was with the different types. When creating the pins, each one had a different type and I could not place them in a single array. However, at the time I wasn't aware there was the `downgrade_output` method that would change the pins to a generic type thus enabling the placing of all pins in a single array. After your suggestion, when I went back to check the hal documentation, it seems like I was looking in the wrong place at the time. I will modify the post sometime soon to include this as an optimized alternative.

[Christian Foucher](https://hashnode.com/@Valda60)

[Jul 21, 2023](https://hashnode.com/posts/esp32-standard-library-embedded-rust-gpio-control/64afe421c3220ca4300ee7a2/comment/64b94706a884f3de56a26afd#reply-64ba7c8d2e3477ebf613485f)

[Omar Hiari](https://hashnode.com/@omarhiari) I have created a suggestion issue in your gitlab repository (because code formatting is ugly in my comment).
