Skip to content

Instantly share code, notes, and snippets.

@rikvermeer
Last active March 9, 2020 21:46
Show Gist options
  • Save rikvermeer/6739cab4d9dba89a08f46fad6ccae343 to your computer and use it in GitHub Desktop.
Save rikvermeer/6739cab4d9dba89a08f46fad6ccae343 to your computer and use it in GitHub Desktop.
Conversiontable for ws2812b chipset
Run SPI/PCM/PWM on 2.4MHz (3x 800 kHz)
Binary conversion with delay
0 => 0 0 0
1 => 1 1 0
800 KHz -> 2.4 MHz
------------------------------------------------------------------------------------------------
000 | 0x00 = 00000000 -> 000 000 000 000 000 000 000 000 = 00000000 00000000 00000000 = 0x000000
001 | 0x01 = 00000001 -> 000 000 000 000 000 000 000 110 = 00000000 00000000 00000110 = 0x000006
... |
255 | 0xff = 11111111 -> 110 110 110 110 110 110 110 110 = 11011011 01101101 10110110 = 0xDB6DB6
------------------------------------------------------------------------------------------------
//Javascript generation of conversion table:
var ConvertBase = function (num) {
return {
from : function (baseFrom) {
return {
to : function (baseTo) {
return parseInt(num, baseFrom).toString(baseTo);
}
};
}
};
};
String.prototype.pad = function(size) {
var s = String(this);
while (s.length < (size || 2)) {s = "0" + s;}
return s;
};
String.prototype.rewrite = function() {
var s = String(this);
return [...s].map(c => c === '0' ? '000' : '110').join('');
};
JSON.stringify(
[...Array(256).keys()].map(i =>
ConvertBase(
ConvertBase(''+i).from(10).to(2).pad(8).rewrite()
).from(2).to(10).pad(0))
);
let a = ["000000","000006","000030","000036","000180","000186","0001b0","0001b6","000c00","000c06","000c30","000c36","000d80","000d86","000db0","000db6","006000","006006","006030","006036","006180","006186","0061b0","0061b6","006c00","006c06","006c30","006c36","006d80","006d86","006db0","006db6","030000","030006","030030","030036","030180","030186","0301b0","0301b6","030c00","030c06","030c30","030c36","030d80","030d86","030db0","030db6","036000","036006","036030","036036","036180","036186","0361b0","0361b6","036c00","036c06","036c30","036c36","036d80","036d86","036db0","036db6","180000","180006","180030","180036","180180","180186","1801b0","1801b6","180c00","180c06","180c30","180c36","180d80","180d86","180db0","180db6","186000","186006","186030","186036","186180","186186","1861b0","1861b6","186c00","186c06","186c30","186c36","186d80","186d86","186db0","186db6","1b0000","1b0006","1b0030","1b0036","1b0180","1b0186","1b01b0","1b01b6","1b0c00","1b0c06","1b0c30","1b0c36","1b0d80","1b0d86","1b0db0","1b0db6","1b6000","1b6006","1b6030","1b6036","1b6180","1b6186","1b61b0","1b61b6","1b6c00","1b6c06","1b6c30","1b6c36","1b6d80","1b6d86","1b6db0","1b6db6","c00000","c00006","c00030","c00036","c00180","c00186","c001b0","c001b6","c00c00","c00c06","c00c30","c00c36","c00d80","c00d86","c00db0","c00db6","c06000","c06006","c06030","c06036","c06180","c06186","c061b0","c061b6","c06c00","c06c06","c06c30","c06c36","c06d80","c06d86","c06db0","c06db6","c30000","c30006","c30030","c30036","c30180","c30186","c301b0","c301b6","c30c00","c30c06","c30c30","c30c36","c30d80","c30d86","c30db0","c30db6","c36000","c36006","c36030","c36036","c36180","c36186","c361b0","c361b6","c36c00","c36c06","c36c30","c36c36","c36d80","c36d86","c36db0","c36db6","d80000","d80006","d80030","d80036","d80180","d80186","d801b0","d801b6","d80c00","d80c06","d80c30","d80c36","d80d80","d80d86","d80db0","d80db6","d86000","d86006","d86030","d86036","d86180","d86186","d861b0","d861b6","d86c00","d86c06","d86c30","d86c36","d86d80","d86d86","d86db0","d86db6","db0000","db0006","db0030","db0036","db0180","db0186","db01b0","db01b6","db0c00","db0c06","db0c30","db0c36","db0d80","db0d86","db0db0","db0db6","db6000","db6006","db6030","db6036","db6180","db6186","db61b0","db61b6","db6c00","db6c06","db6c30","db6c36","db6d80","db6d86","db6db0","db6db6"]
JSON.stringify(a.map(b => [b.slice(0,2), b.slice(2,4), b.slice(4,6)]))
let b = [["00","00","00"],["00","00","06"],["00","00","30"],["00","00","36"],["00","01","80"],["00","01","86"],["00","01","b0"],["00","01","b6"],["00","0c","00"],["00","0c","06"],["00","0c","30"],["00","0c","36"],["00","0d","80"],["00","0d","86"],["00","0d","b0"],["00","0d","b6"],["00","60","00"],["00","60","06"],["00","60","30"],["00","60","36"],["00","61","80"],["00","61","86"],["00","61","b0"],["00","61","b6"],["00","6c","00"],["00","6c","06"],["00","6c","30"],["00","6c","36"],["00","6d","80"],["00","6d","86"],["00","6d","b0"],["00","6d","b6"],["03","00","00"],["03","00","06"],["03","00","30"],["03","00","36"],["03","01","80"],["03","01","86"],["03","01","b0"],["03","01","b6"],["03","0c","00"],["03","0c","06"],["03","0c","30"],["03","0c","36"],["03","0d","80"],["03","0d","86"],["03","0d","b0"],["03","0d","b6"],["03","60","00"],["03","60","06"],["03","60","30"],["03","60","36"],["03","61","80"],["03","61","86"],["03","61","b0"],["03","61","b6"],["03","6c","00"],["03","6c","06"],["03","6c","30"],["03","6c","36"],["03","6d","80"],["03","6d","86"],["03","6d","b0"],["03","6d","b6"],["18","00","00"],["18","00","06"],["18","00","30"],["18","00","36"],["18","01","80"],["18","01","86"],["18","01","b0"],["18","01","b6"],["18","0c","00"],["18","0c","06"],["18","0c","30"],["18","0c","36"],["18","0d","80"],["18","0d","86"],["18","0d","b0"],["18","0d","b6"],["18","60","00"],["18","60","06"],["18","60","30"],["18","60","36"],["18","61","80"],["18","61","86"],["18","61","b0"],["18","61","b6"],["18","6c","00"],["18","6c","06"],["18","6c","30"],["18","6c","36"],["18","6d","80"],["18","6d","86"],["18","6d","b0"],["18","6d","b6"],["1b","00","00"],["1b","00","06"],["1b","00","30"],["1b","00","36"],["1b","01","80"],["1b","01","86"],["1b","01","b0"],["1b","01","b6"],["1b","0c","00"],["1b","0c","06"],["1b","0c","30"],["1b","0c","36"],["1b","0d","80"],["1b","0d","86"],["1b","0d","b0"],["1b","0d","b6"],["1b","60","00"],["1b","60","06"],["1b","60","30"],["1b","60","36"],["1b","61","80"],["1b","61","86"],["1b","61","b0"],["1b","61","b6"],["1b","6c","00"],["1b","6c","06"],["1b","6c","30"],["1b","6c","36"],["1b","6d","80"],["1b","6d","86"],["1b","6d","b0"],["1b","6d","b6"],["c0","00","00"],["c0","00","06"],["c0","00","30"],["c0","00","36"],["c0","01","80"],["c0","01","86"],["c0","01","b0"],["c0","01","b6"],["c0","0c","00"],["c0","0c","06"],["c0","0c","30"],["c0","0c","36"],["c0","0d","80"],["c0","0d","86"],["c0","0d","b0"],["c0","0d","b6"],["c0","60","00"],["c0","60","06"],["c0","60","30"],["c0","60","36"],["c0","61","80"],["c0","61","86"],["c0","61","b0"],["c0","61","b6"],["c0","6c","00"],["c0","6c","06"],["c0","6c","30"],["c0","6c","36"],["c0","6d","80"],["c0","6d","86"],["c0","6d","b0"],["c0","6d","b6"],["c3","00","00"],["c3","00","06"],["c3","00","30"],["c3","00","36"],["c3","01","80"],["c3","01","86"],["c3","01","b0"],["c3","01","b6"],["c3","0c","00"],["c3","0c","06"],["c3","0c","30"],["c3","0c","36"],["c3","0d","80"],["c3","0d","86"],["c3","0d","b0"],["c3","0d","b6"],["c3","60","00"],["c3","60","06"],["c3","60","30"],["c3","60","36"],["c3","61","80"],["c3","61","86"],["c3","61","b0"],["c3","61","b6"],["c3","6c","00"],["c3","6c","06"],["c3","6c","30"],["c3","6c","36"],["c3","6d","80"],["c3","6d","86"],["c3","6d","b0"],["c3","6d","b6"],["d8","00","00"],["d8","00","06"],["d8","00","30"],["d8","00","36"],["d8","01","80"],["d8","01","86"],["d8","01","b0"],["d8","01","b6"],["d8","0c","00"],["d8","0c","06"],["d8","0c","30"],["d8","0c","36"],["d8","0d","80"],["d8","0d","86"],["d8","0d","b0"],["d8","0d","b6"],["d8","60","00"],["d8","60","06"],["d8","60","30"],["d8","60","36"],["d8","61","80"],["d8","61","86"],["d8","61","b0"],["d8","61","b6"],["d8","6c","00"],["d8","6c","06"],["d8","6c","30"],["d8","6c","36"],["d8","6d","80"],["d8","6d","86"],["d8","6d","b0"],["d8","6d","b6"],["db","00","00"],["db","00","06"],["db","00","30"],["db","00","36"],["db","01","80"],["db","01","86"],["db","01","b0"],["db","01","b6"],["db","0c","00"],["db","0c","06"],["db","0c","30"],["db","0c","36"],["db","0d","80"],["db","0d","86"],["db","0d","b0"],["db","0d","b6"],["db","60","00"],["db","60","06"],["db","60","30"],["db","60","36"],["db","61","80"],["db","61","86"],["db","61","b0"],["db","61","b6"],["db","6c","00"],["db","6c","06"],["db","6c","30"],["db","6c","36"],["db","6d","80"],["db","6d","86"],["db","6d","b0"],["db","6d","b6"]]
JSON.stringify(b.map(c => c.map(d => parseInt(d,16)))
const table = [[0,0,0],[0,0,6],[0,0,48],[0,0,54],[0,1,128],[0,1,134],[0,1,176],[0,1,182],[0,12,0],[0,12,6],[0,12,48],[0,12,54],[0,13,128],[0,13,134],[0,13,176],[0,13,182],[0,96,0],[0,96,6],[0,96,48],[0,96,54],[0,97,128],[0,97,134],[0,97,176],[0,97,182],[0,108,0],[0,108,6],[0,108,48],[0,108,54],[0,109,128],[0,109,134],[0,109,176],[0,109,182],[3,0,0],[3,0,6],[3,0,48],[3,0,54],[3,1,128],[3,1,134],[3,1,176],[3,1,182],[3,12,0],[3,12,6],[3,12,48],[3,12,54],[3,13,128],[3,13,134],[3,13,176],[3,13,182],[3,96,0],[3,96,6],[3,96,48],[3,96,54],[3,97,128],[3,97,134],[3,97,176],[3,97,182],[3,108,0],[3,108,6],[3,108,48],[3,108,54],[3,109,128],[3,109,134],[3,109,176],[3,109,182],[24,0,0],[24,0,6],[24,0,48],[24,0,54],[24,1,128],[24,1,134],[24,1,176],[24,1,182],[24,12,0],[24,12,6],[24,12,48],[24,12,54],[24,13,128],[24,13,134],[24,13,176],[24,13,182],[24,96,0],[24,96,6],[24,96,48],[24,96,54],[24,97,128],[24,97,134],[24,97,176],[24,97,182],[24,108,0],[24,108,6],[24,108,48],[24,108,54],[24,109,128],[24,109,134],[24,109,176],[24,109,182],[27,0,0],[27,0,6],[27,0,48],[27,0,54],[27,1,128],[27,1,134],[27,1,176],[27,1,182],[27,12,0],[27,12,6],[27,12,48],[27,12,54],[27,13,128],[27,13,134],[27,13,176],[27,13,182],[27,96,0],[27,96,6],[27,96,48],[27,96,54],[27,97,128],[27,97,134],[27,97,176],[27,97,182],[27,108,0],[27,108,6],[27,108,48],[27,108,54],[27,109,128],[27,109,134],[27,109,176],[27,109,182],[192,0,0],[192,0,6],[192,0,48],[192,0,54],[192,1,128],[192,1,134],[192,1,176],[192,1,182],[192,12,0],[192,12,6],[192,12,48],[192,12,54],[192,13,128],[192,13,134],[192,13,176],[192,13,182],[192,96,0],[192,96,6],[192,96,48],[192,96,54],[192,97,128],[192,97,134],[192,97,176],[192,97,182],[192,108,0],[192,108,6],[192,108,48],[192,108,54],[192,109,128],[192,109,134],[192,109,176],[192,109,182],[195,0,0],[195,0,6],[195,0,48],[195,0,54],[195,1,128],[195,1,134],[195,1,176],[195,1,182],[195,12,0],[195,12,6],[195,12,48],[195,12,54],[195,13,128],[195,13,134],[195,13,176],[195,13,182],[195,96,0],[195,96,6],[195,96,48],[195,96,54],[195,97,128],[195,97,134],[195,97,176],[195,97,182],[195,108,0],[195,108,6],[195,108,48],[195,108,54],[195,109,128],[195,109,134],[195,109,176],[195,109,182],[216,0,0],[216,0,6],[216,0,48],[216,0,54],[216,1,128],[216,1,134],[216,1,176],[216,1,182],[216,12,0],[216,12,6],[216,12,48],[216,12,54],[216,13,128],[216,13,134],[216,13,176],[216,13,182],[216,96,0],[216,96,6],[216,96,48],[216,96,54],[216,97,128],[216,97,134],[216,97,176],[216,97,182],[216,108,0],[216,108,6],[216,108,48],[216,108,54],[216,109,128],[216,109,134],[216,109,176],[216,109,182],[219,0,0],[219,0,6],[219,0,48],[219,0,54],[219,1,128],[219,1,134],[219,1,176],[219,1,182],[219,12,0],[219,12,6],[219,12,48],[219,12,54],[219,13,128],[219,13,134],[219,13,176],[219,13,182],[219,96,0],[219,96,6],[219,96,48],[219,96,54],[219,97,128],[219,97,134],[219,97,176],[219,97,182],[219,108,0],[219,108,6],[219,108,48],[219,108,54],[219,109,128],[219,109,134],[219,109,176],[219,109,182]]
[...table[255], ...table[155], ...table[0]]
[219, 109, 182, 192, 108, 54, 0, 0, 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment