# What's the "latch" operation in rockpool?

**URL:** <https://forums.pimoroni.com/t/whats-the-latch-operation-in-rockpool/2780>\
**Category:** Flotilla\
**Created:** [August 3, 2016, 9:56am UTC](https://forums.pimoroni.com/t/whats-the-latch-operation-in-rockpool/2780 "2016-08-03T09:56:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tenpn](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tenpn/32/1439_2.png) [@tenpn](https://forums.pimoroni.com/u/tenpn)\
**Post date:** [August 3, 2016, 9:56am UTC](https://forums.pimoroni.com/t/whats-the-latch-operation-in-rockpool/2780/1 "2016-08-03T09:56:41Z")

</div>

I’ve had a play with it merging a slider and a clock input, but couldn’t see rhyme or reason in the output. Any ideas?

---

<div class="post-metadata">

**Author:** ![gadgetoid](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/gadgetoid/32/13_2.png) [@gadgetoid](https://forums.pimoroni.com/u/gadgetoid)\
**Post date:** [August 3, 2016, 10:16am UTC](https://forums.pimoroni.com/t/whats-the-latch-operation-in-rockpool/2780/2 "2016-08-03T10:16:33Z")

</div>

“Latch” in Rockpool is effectively one “bit” of memory. It has two inputs:

- The top input is the value being input, and which you want to store
- The bottom input is the latch signal, which locks the value into the latch

The exact logic of latch is as follows, where `latch_value` is the latch signal, and `input_value` is the data signal:

```javascript
if( latch_value > 0.5 && this.last_value <= 0.5 ){
    this.latched_value = this.input_value
}
this.last_value = latch_value 

```

What it’s effectively saying is:

If the latch signal crosses half way from bottom to top (known as a “rising edge” in electronics lingo) then save the current input value.

Latch will always return the last value which was latched into it, so you can use it to dial in and save a brightness value for example.

If you have the Noisemaker kit, or a Touch, Rainbow and Dial then the following Rockpool save will show you how to use the dial to control Red, Green and Blue by latching each colour value into the Rainbow using Touch 1, 2 and 3:

Save the following as: `latch-example.rpl` and drag ‘n’ drop it into the file drop zone of the Rockpool load dialog.

```auto
_rockpool_save([{"enabled":true,"input":{"key":"0_2_dial_position","option":-1,"value":-1},"output":{"key":"0_0_rainbow_LED","option":0},"converters":[{"key":"latch","child":{"enabled":true,"input":{"key":"0_4_touch_button","option":0,"value":-1},"output":{"key":"latch","option":-1},"converters":[]}},{"key":"noop"},{"key":"noop"}]},{"enabled":true,"input":{"key":"0_2_dial_position","option":-1,"value":-1},"output":{"key":"0_0_rainbow_LED","option":1},"converters":[{"key":"latch","child":{"enabled":true,"input":{"key":"0_4_touch_button","option":1,"value":-1},"output":{"key":"latch","option":-1},"converters":[]}},{"key":"noop"},{"key":"noop"}]},{"enabled":true,"input":{"key":"0_2_dial_position","option":-1,"value":-1},"output":{"key":"0_0_rainbow_LED","option":2},"converters":[{"key":"latch","child":{"enabled":true,"input":{"key":"0_4_touch_button","option":2,"value":-1},"output":{"key":"latch","option":-1},"converters":[]}},{"key":"noop"},{"key":"noop"}]}]);

```

---

<div class="post-metadata">

**Author:** ![tenpn](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tenpn/32/1439_2.png) [@tenpn](https://forums.pimoroni.com/u/tenpn)\
**Post date:** [August 3, 2016, 10:28am UTC](https://forums.pimoroni.com/t/whats-the-latch-operation-in-rockpool/2780/3 "2016-08-03T10:28:55Z")

</div>

Nice! Thanks for the info.

---

<div class="post-metadata">

**Author:** ![gadgetoid](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/gadgetoid/32/13_2.png) [@gadgetoid](https://forums.pimoroni.com/u/gadgetoid)\
**Post date:** [August 3, 2016, 10:35am UTC](https://forums.pimoroni.com/t/whats-the-latch-operation-in-rockpool/2780/4 "2016-08-03T10:35:24Z")

</div>

You’re welcome! It’s by far one of the most opaque widgets in Rockpool, but it’s too useful to leave out! There were others that didn’t quite make the cut.

---

<div class="post-metadata">

**Author:** ![tenpn](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tenpn/32/1439_2.png) [@tenpn](https://forums.pimoroni.com/u/tenpn)\
**Post date:** [August 3, 2016, 10:00pm UTC](https://forums.pimoroni.com/t/whats-the-latch-operation-in-rockpool/2780/5 "2016-08-03T22:00:12Z")

</div>

Sorry, short followup. What’s the rockpool “load dialog”? I’m using the OSX prerelease software, and my rockpool has an anchor at the bottom that opens a drawer with a load circle. If I tap that, nothing happens. If I drag an rpl file on to it, the browser (chrome) interprets that as wanting the file to be opened in the browser, which obviously doesn’t work.

---

<div class="post-metadata">

**Author:** ![gadgetoid](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/gadgetoid/32/13_2.png) [@gadgetoid](https://forums.pimoroni.com/u/gadgetoid)\
**Post date:** [August 3, 2016, 10:48pm UTC](https://forums.pimoroni.com/t/whats-the-latch-operation-in-rockpool/2780/6 "2016-08-03T22:48:52Z")

</div>

> [@tenpn](#):
>
> Sorry, short followup. What’s the rockpool “load dialog”? I’m using the OSX prerelease software, and my rockpool has an anchor at the bottom that opens a drawer with a load circle. If I tap that, nothing happens. If I drag an rpl file on to it, the browser (chrome) interprets that as wanting the file to be opened in the browser, which obviously doesn’t work.

That will now be somewhat old code, you should use the Rockpool version at Flotil.la here: [http://flotil.la/rockpool/](http://flotil.la/rockpool/)

Hopefully it’ll work with your Dock/Daemon versions.

---

<div class="post-metadata">

**Author:** ![tenpn](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tenpn/32/1439_2.png) [@tenpn](https://forums.pimoroni.com/u/tenpn)\
**Post date:** [August 6, 2016, 1:13pm UTC](https://forums.pimoroni.com/t/whats-the-latch-operation-in-rockpool/2780/7 "2016-08-06T13:13:24Z")

</div>

Yes, that’s working! Thanks.
