This post describes the Wheel function that is part of the strandtest example included within the NeoPixel library.

I’m writing it as a preamble to a planned series of articles about my experiments with an Arduino Gemma and a NeoPixel ring with 16 RGB LEDs.

The Wheel function takes a value from 0 to 255 (inclusive) and maps that onto a red-green-blue color wheel. Internally, it computes a value for the red, green, and blue components of the result. Those three parts are combined by the strip.Color function to return a 32-bit value representing that color.

The Wheel function may eventually be included in the NeoPixel library, but for now, include it in each of your sketches.

uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

From a quick code reading, we can see that the numbers from 0 to 255 are divided into three sections: 0-85, 86-170, and 171-255. But what we care about more than the math are the colors that result.

Let’s build a table showing how an input value is transformed. I wrote a little Python code to take each number from 0 to 255 and give the resulting red, green, and blue values. In addition, I added the HTML hex color code and the color itself. Maybe it’ll help you when incorporating Wheel into your own designs.

The color wheel only includes red, green, and blue combinations. There is no black and no white. You may need to use other techniques or in addition to the Wheel function.

Get ready for some scrolling!

</tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </tbody> </table>
position01234567
Red255252249246243240237234
Green036912151821
Blue00000000
HTML color code#ff0000</td>#fc0300</td>#f90600</td>#f60900</td>#f30c00</td>#f00f00</td>#ed1200</td>#ea1500</td></tr>
HTML color
position89101112131415
Red231228225222219216213210
Green2427303336394245
Blue00000000
HTML color code#e71800</td>#e41b00</td>#e11e00</td>#de2100</td>#db2400</td>#d82700</td>#d52a00</td>#d22d00</td></tr>
HTML color
position1617181920212223
Red207204201198195192189186
Green4851545760636669
Blue00000000
HTML color code#cf3000</td>#cc3300</td>#c93600</td>#c63900</td>#c33c00</td>#c03f00</td>#bd4200</td>#ba4500</td></tr>
HTML color
position2425262728293031
Red183180177174171168165162
Green7275788184879093
Blue00000000
HTML color code#b74800</td>#b44b00</td>#b14e00</td>#ae5100</td>#ab5400</td>#a85700</td>#a55a00</td>#a25d00</td></tr>
HTML color
position3233343536373839
Red159156153150147144141138
Green9699102105108111114117
Blue00000000
HTML color code#9f6000</td>#9c6300</td>#996600</td>#966900</td>#936c00</td>#906f00</td>#8d7200</td>#8a7500</td></tr>
HTML color
position4041424344454647
Red135132129126123120117114
Green120123126129132135138141
Blue00000000
HTML color code#877800</td>#847b00</td>#817e00</td>#7e8100</td>#7b8400</td>#788700</td>#758a00</td>#728d00</td></tr>
HTML color
position4849505152535455
Red11110810510299969390
Green144147150153156159162165
Blue00000000
HTML color code#6f9000</td>#6c9300</td>#699600</td>#669900</td>#639c00</td>#609f00</td>#5da200</td>#5aa500</td></tr>
HTML color
position5657585960616263
Red8784817875726966
Green168171174177180183186189
Blue00000000
HTML color code#57a800</td>#54ab00</td>#51ae00</td>#4eb100</td>#4bb400</td>#48b700</td>#45ba00</td>#42bd00</td></tr>
HTML color
position6465666768697071
Red6360575451484542
Green192195198201204207210213
Blue00000000
HTML color code#3fc000</td>#3cc300</td>#39c600</td>#36c900</td>#33cc00</td>#30cf00</td>#2dd200</td>#2ad500</td></tr>
HTML color
position7273747576777879
Red3936333027242118
Green216219222225228231234237
Blue00000000
HTML color code#27d800</td>#24db00</td>#21de00</td>#1ee100</td>#1be400</td>#18e700</td>#15ea00</td>#12ed00</td></tr>
HTML color
position8081828384858687
Red1512963000
Green240243246249252255252249
Blue00000036
HTML color code#0ff000</td>#0cf300</td>#09f600</td>#06f900</td>#03fc00</td>#00ff00</td>#00fc03</td>#00f906</td></tr>
HTML color
position8889909192939495
Red00000000
Green246243240237234231228225
Blue912151821242730
HTML color code#00f609</td>#00f30c</td>#00f00f</td>#00ed12</td>#00ea15</td>#00e718</td>#00e41b</td>#00e11e</td></tr>
HTML color
position96979899100101102103
Red00000000
Green222219216213210207204201
Blue3336394245485154
HTML color code#00de21</td>#00db24</td>#00d827</td>#00d52a</td>#00d22d</td>#00cf30</td>#00cc33</td>#00c936</td></tr>
HTML color
position104105106107108109110111
Red00000000
Green198195192189186183180177
Blue5760636669727578
HTML color code#00c639</td>#00c33c</td>#00c03f</td>#00bd42</td>#00ba45</td>#00b748</td>#00b44b</td>#00b14e</td></tr>
HTML color
position112113114115116117118119
Red00000000
Green174171168165162159156153
Blue81848790939699102
HTML color code#00ae51</td>#00ab54</td>#00a857</td>#00a55a</td>#00a25d</td>#009f60</td>#009c63</td>#009966</td></tr>
HTML color
position120121122123124125126127
Red00000000
Green150147144141138135132129
Blue105108111114117120123126
HTML color code#009669</td>#00936c</td>#00906f</td>#008d72</td>#008a75</td>#008778</td>#00847b</td>#00817e</td></tr>
HTML color
position128129130131132133134135
Red00000000
Green126123120117114111108105
Blue129132135138141144147150
HTML color code#007e81</td>#007b84</td>#007887</td>#00758a</td>#00728d</td>#006f90</td>#006c93</td>#006996</td></tr>
HTML color
position136137138139140141142143
Red00000000
Green10299969390878481
Blue153156159162165168171174
HTML color code#006699</td>#00639c</td>#00609f</td>#005da2</td>#005aa5</td>#0057a8</td>#0054ab</td>#0051ae</td></tr>
HTML color
position144145146147148149150151
Red00000000
Green7875726966636057
Blue177180183186189192195198
HTML color code#004eb1</td>#004bb4</td>#0048b7</td>#0045ba</td>#0042bd</td>#003fc0</td>#003cc3</td>#0039c6</td></tr>
HTML color
position152153154155156157158159
Red00000000
Green5451484542393633
Blue201204207210213216219222
HTML color code#0036c9</td>#0033cc</td>#0030cf</td>#002dd2</td>#002ad5</td>#0027d8</td>#0024db</td>#0021de</td></tr>
HTML color
position160161162163164165166167
Red00000000
Green302724211815129
Blue225228231234237240243246
HTML color code#001ee1</td>#001be4</td>#0018e7</td>#0015ea</td>#0012ed</td>#000ff0</td>#000cf3</td>#0009f6</td></tr>
HTML color
position168169170171172173174175
Red0003691215
Green63000000
Blue249252255252249246243240
HTML color code#0006f9</td>#0003fc</td>#0000ff</td>#0300fc</td>#0600f9</td>#0900f6</td>#0c00f3</td>#0f00f0</td></tr>
HTML color
position176177178179180181182183
Red1821242730333639
Green00000000
Blue237234231228225222219216
HTML color code#1200ed</td>#1500ea</td>#1800e7</td>#1b00e4</td>#1e00e1</td>#2100de</td>#2400db</td>#2700d8</td></tr>
HTML color
position184185186187188189190191
Red4245485154576063
Green00000000
Blue213210207204201198195192
HTML color code#2a00d5</td>#2d00d2</td>#3000cf</td>#3300cc</td>#3600c9</td>#3900c6</td>#3c00c3</td>#3f00c0</td></tr>
HTML color
position192193194195196197198199
Red6669727578818487
Green00000000
Blue189186183180177174171168
HTML color code#4200bd</td>#4500ba</td>#4800b7</td>#4b00b4</td>#4e00b1</td>#5100ae</td>#5400ab</td>#5700a8</td></tr>
HTML color
position200201202203204205206207
Red90939699102105108111
Green00000000
Blue165162159156153150147144
HTML color code#5a00a5</td>#5d00a2</td>#60009f</td>#63009c</td>#660099</td>#690096</td>#6c0093</td>#6f0090</td></tr>
HTML color
position208209210211212213214215
Red114117120123126129132135
Green00000000
Blue141138135132129126123120
HTML color code#72008d</td>#75008a</td>#780087</td>#7b0084</td>#7e0081</td>#81007e</td>#84007b</td>#870078</td></tr>
HTML color
position216217218219220221222223
Red138141144147150153156159
Green00000000
Blue1171141111081051029996
HTML color code#8a0075</td>#8d0072</td>#90006f</td>#93006c</td>#960069</td>#990066</td>#9c0063</td>#9f0060</td></tr>
HTML color
position224225226227228229230231
Red162165168171174177180183
Green00000000
Blue9390878481787572
HTML color code#a2005d</td>#a5005a</td>#a80057</td>#ab0054</td>#ae0051</td>#b1004e</td>#b4004b</td>#b70048</td></tr>
HTML color
position232233234235236237238239
Red186189192195198201204207
Green00000000
Blue6966636057545148
HTML color code#ba0045</td>#bd0042</td>#c0003f</td>#c3003c</td>#c60039</td>#c90036</td>#cc0033</td>#cf0030</td></tr>
HTML color
position240241242243244245246247
Red210213216219222225228231
Green00000000
Blue4542393633302724
HTML color code#d2002d</td>#d5002a</td>#d80027</td>#db0024</td>#de0021</td>#e1001e</td>#e4001b</td>#e70018</td></tr>
HTML color
position248249250251252253254255
Red234237240243246249252255
Green00000000
Blue211815129630
HTML color code#ea0015</td>#ed0012</td>#f0000f</td>#f3000c</td>#f60009</td>#f90006</td>#fc0003</td>#ff0000</td></tr>
HTML color