Gemma+NeoPixel 0: Wheel

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!

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