# Using a GPIO Input to alter a pattern

**URL:** <https://forum.electromage.com/t/using-a-gpio-input-to-alter-a-pattern/4556>\
**Category:** Troubleshooting\
**Created:** [October 16, 2025, 5:09am UTC](https://forum.electromage.com/t/using-a-gpio-input-to-alter-a-pattern/4556 "2025-10-16T05:09:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZacharyRD](https://forum.electromage.com/user_avatar/forum.electromage.com/zacharyrd/32/124_2.png) [@ZacharyRD](https://forum.electromage.com/u/ZacharyRD)\
**Post date:** [October 16, 2025, 5:09am UTC](https://forum.electromage.com/t/using-a-gpio-input-to-alter-a-pattern/4556/1 "2025-10-16T05:09:13Z")

</div>

I’m a little bit lost on how to get started both on the hardware and software side of things, and searching the forums didn’t help enough. I have an ESP32 that’s doing a bunch of interactive things, but in the end, will be able to send a wired signal (for prototyping, it lights up a single bare LED) when a successful event happens. In production, when that successful event happens, I want a PixelBlaze LED pattern to turn on, and then turn off again 10 seconds later.

I’m both not sure how to use a GPIO input pin on a PixelBlaze v3 and how to do this in code. I think from the documentation here: [https://electromage.com/docs/GPIO](https://electromage.com/docs/GPIO) that I can use IO25 (or IO26) to do this, with I think the digitalRead(26,1) command, but am not sure how to use it correctly and how to incorporate it in existing patterns.

Ideally, I’d wire the ESP32’s digital out on a pin to the digitalread pin of the PixelBlaze, and when a signal was sent, it’d set the brightness of the pattern from 0 to “regular” for 10 seconds and then turn off again – but this is going beyond what I’ve done before and know how to do. Thanks for helping me with my sometimes limited background in the fundementals of electronics wiring and coding…

---

<div class="post-metadata">

**Author:** ![wizard](https://forum.electromage.com/user_avatar/forum.electromage.com/wizard/32/4_2.png) [@wizard](https://forum.electromage.com/u/wizard)\
**Post date:** [October 16, 2025, 4:31pm UTC](https://forum.electromage.com/t/using-a-gpio-input-to-alter-a-pattern/4556/2 "2025-10-16T16:31:48Z")

</div>

Two approaches.

You could do this in one pattern, basically use if in code to do something when a gpio is a particular level. Could use delta to control timing to have it run for a minimum period or fade in/out.

Another way is to use playlists and the sequencer api. You can jump to a specific playlist position.

some related posts:

> [@The Technocolour Dreamcoat, phone-free Burning Man 2023 edition!](https://forum.electromage.com/t/the-technocolour-dreamcoat-phone-free-burning-man-2023-edition/3115/3):
>
> Well, sure. Here’s the code: export function beforeRender(delta) { // ... // enable next/forward buttons debounceNext(delta) debouncePrev(delta) } export var analogInputs var DEBOUNCE\_TIME = 40; var nextBtnState; var nextBtnTimer; function debounceNext(delta) { var newState = analogInputs[2] \> 0.5; if (newState == nextBtnState) { nextBtnTimer = 0; } else { nextBtnTimer += delta; } if (nextBtnTimer \> DEBOUNCE\_TIME) { nextBtnState = newState; if (nextBtnStat…

> [@API for changing patterns (… in a playlist)?](https://forum.electromage.com/t/api-for-changing-patterns-in-a-playlist/3108/5):
>
> Good news @ratkins ! Here’s a beta build with sequencer APIs. This should let you implement what you are looking for with a bit of pattern code. You’ll need to copy some code to each pattern for reading/debouncing SB inputs and going next/prev, but cleaner than making a mega pattern. Standard: [v3.49.pb32.stfu](https://forum.electromage.com/uploads/short-url/nnju0XfFsrRvgdXVvMo33WiVfnV.stfu) (1.4 MB) Pico: [v3.49.pico32.stfu](https://forum.electromage.com/uploads/short-url/vFY0A0UZaj7ueBmc2fRj4lJQNu6.stfu) (1.4 MB) Docs haven’t been updated, but here’s what’s new: sequencerNext() Universal advance to next pattern, pretty much the same as button press. Th…

Hardware wise, if it’s 3.3v then you can wire it directly.

---

<div class="post-metadata">

**Author:** ![ZacharyRD](https://forum.electromage.com/user_avatar/forum.electromage.com/zacharyrd/32/124_2.png) [@ZacharyRD](https://forum.electromage.com/u/ZacharyRD)\
**Post date:** [October 17, 2025, 6:08am UTC](https://forum.electromage.com/t/using-a-gpio-input-to-alter-a-pattern/4556/3 "2025-10-17T06:08:40Z")

</div>

Thanks a lot! I’m up and running. Yes, it’s a 3.3v ESP32 controlling everything. I didn’t realize it was as simple as “wire the ESP32 to the GPIO pin on the PixelBlaze and give them common ground and you’re done” for wiring.

I also didn’t realize ChatGPT finally understands the PixelBlaze – it didn’t a year or so ago, really. Since I found the existing documentation on [https://electromage.com/docs/GPIO](https://electromage.com/docs/GPIO) a bit cryptic as a beginner, I’ll write out what I did as documentation for anyone else reading this later:

ESP32 GPIO27 –\> directly to PixelBlaze GPIO Pin 25.  
ESP32 Ground –\> Common Ground with PixelBlaze.

About as simple of wiring as it gets.

Then I used this code to as my test this evening, and it worked fine. I don’t vouch for the code, really (it could be overly complicated in terms of handling the bounce or falling edge, and AI had a very heavy hand in writing it), but it made sense to me when reading it, and does what what I wanted really cleanly as a v1.

```auto
// ==== CONFIG ====
// Choose the actual GPIO you’re using on the Pixelblaze (e.g., 0, 25, or 26 on V3)
var BUTTON_PIN = 25

// If your ESP32 pulls the Pixelblaze pin to GND when “pressed”, use INPUT_PULLUP
pinMode(BUTTON_PIN, INPUT_PULLUP)

// ==== STATE ====
var lastBtn = 1 // matches INPUT_PULLUP idle = 1 (not pressed)
var triggered = false
var remainingMs = 0 // countdown in milliseconds

// How long to stay active after a press
var TRIGGER_MS = 2000 // 2 seconds

export function beforeRender(delta) {
// Read button: with INPUT_PULLUP, pressed == 0, released == 1
var btn = digitalRead(BUTTON_PIN)

// Detect falling edge (released->pressed)
if (lastBtn == 1 && btn == 0) {
triggered = true
remainingMs = TRIGGER_MS
}
lastBtn = btn

// Countdown while triggered
if (triggered) {
remainingMs -= delta
if (remainingMs <= 0) {
triggered = false
remainingMs = 0
}
}
}

export function render(index) {
if (triggered) {
rgb(1, 1, 1) // white for 10 s after a press. Replace with any other "on press" code.
} else {
rgb(1, 0, 0) // red otherwise. Replace with any other "when not pressed" code. 
}
}

```

---

<div class="post-metadata">

**Author:** ![system](https://forum.electromage.com/uploads/default/original/1X/98123d16088a5451b5a585e24c0f2a40dd76061e.png) [@system](https://forum.electromage.com/u/system)\
**Post date:** [February 14, 2026, 6:09am UTC](https://forum.electromage.com/t/using-a-gpio-input-to-alter-a-pattern/4556/4 "2026-02-14T06:09:12Z")

</div>

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.
