# One Button Press, cycle through 3 Yeelight Colours

**URL:** https://discourse.nodered.org/t/one-button-press-cycle-through-3-yeelight-colours/11607
**Category:** General
**Created:** [27 May 2019 17:25 UTC](https://discourse.nodered.org/t/one-button-press-cycle-through-3-yeelight-colours/11607 "2019-05-27T17:25:37Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [27 May 2019 20:08 UTC](https://discourse.nodered.org/t/one-button-press-cycle-through-3-yeelight-colours/11607/7 "2019-05-27T20:08:21Z")

</div>

High level solution logic explanation:  
Hold current state in node red as index in array of all possible states.  
On input add 1 to index but check If new index is equal with array length set index to 0.  
Store index as current index  
Send new state got from array from that index.

Edit:  
Made correction in order of steps. Asking array elements by index should always stay in boundaries.

---

_[View the full topic](https://discourse.nodered.org/t/one-button-press-cycle-through-3-yeelight-colours/11607)._
