Peter Hall
5 years ago
committed by
Randy Mackay
2 changed files with 795 additions and 0 deletions
@ -0,0 +1,539 @@
@@ -0,0 +1,539 @@
|
||||
--[[ |
||||
Script to control LED strips based on the roll of the aircraft. This is an example to demonstrate |
||||
the LED interface for WS2812 LEDs |
||||
--]] |
||||
|
||||
--[[ |
||||
for this demo we will use a single strip with 30 LEDs |
||||
--]] |
||||
local matrix_x = 7 |
||||
local matrix_y = 7 |
||||
|
||||
-- matrix to convert from x y pos to location in the strip |
||||
local id = {} |
||||
-- because my strips go diagonally to get the led's closer together this is a odd ordering |
||||
id[1] = {} |
||||
id[1][1] = 21 |
||||
id[1][2] = 20 |
||||
id[1][3] = 10 |
||||
id[1][4] = 9 |
||||
id[1][5] = 3 |
||||
id[1][6] = 2 |
||||
id[1][7] = 0 |
||||
|
||||
id[2] = {} |
||||
id[2][1] = 33 |
||||
id[2][2] = 22 |
||||
id[2][3] = 19 |
||||
id[2][4] = 11 |
||||
id[2][5] = 8 |
||||
id[2][6] = 4 |
||||
id[2][7] = 1 |
||||
|
||||
id[3] = {} |
||||
id[3][1] = 34 |
||||
id[3][2] = 32 |
||||
id[3][3] = 23 |
||||
id[3][4] = 18 |
||||
id[3][5] = 12 |
||||
id[3][6] = 7 |
||||
id[3][7] = 5 |
||||
|
||||
id[4] = {} |
||||
id[4][1] = 42 |
||||
id[4][2] = 35 |
||||
id[4][3] = 31 |
||||
id[4][4] = 24 |
||||
id[4][5] = 17 |
||||
id[4][6] = 13 |
||||
id[4][7] = 6 |
||||
|
||||
id[5] = {} |
||||
id[5][1] = 43 |
||||
id[5][2] = 41 |
||||
id[5][3] = 36 |
||||
id[5][4] = 30 |
||||
id[5][5] = 25 |
||||
id[5][6] = 16 |
||||
id[5][7] = 14 |
||||
|
||||
id[6] = {} |
||||
id[6][1] = 47 |
||||
id[6][2] = 44 |
||||
id[6][3] = 40 |
||||
id[6][4] = 37 |
||||
id[6][5] = 29 |
||||
id[6][6] = 26 |
||||
id[6][7] = 15 |
||||
|
||||
id[7] = {} |
||||
id[7][1] = 48 |
||||
id[7][2] = 46 |
||||
id[7][3] = 45 |
||||
id[7][4] = 39 |
||||
id[7][5] = 38 |
||||
id[7][6] = 28 |
||||
id[7][7] = 27 |
||||
|
||||
-- ArduPilot logo 7 x 48, RGB |
||||
image = {} |
||||
image[1] = {} |
||||
image[2] = {} |
||||
image[3] = {} |
||||
image[4] = {} |
||||
image[5] = {} |
||||
image[6] = {} |
||||
image[7] = {} |
||||
|
||||
image[1][1] = {0, 0, 0} |
||||
image[2][1] = {0, 0, 0} |
||||
image[3][1] = {0, 0, 0} |
||||
image[4][1] = {0, 0, 0} |
||||
image[5][1] = {0, 0, 0} |
||||
image[6][1] = {0, 0, 0} |
||||
image[7][1] = {0, 0, 0} |
||||
|
||||
image[1][2] = {0, 0, 0} |
||||
image[2][2] = {0, 0, 0} |
||||
image[3][2] = {0, 0, 0} |
||||
image[4][2] = {0, 0, 0} |
||||
image[5][2] = {0, 0, 0} |
||||
image[6][2] = {0, 0, 0} |
||||
image[7][2] = {191, 191, 191} |
||||
|
||||
image[1][3] = {0, 0, 0} |
||||
image[2][3] = {0, 0, 0} |
||||
image[3][3] = {0, 0, 0} |
||||
image[4][3] = {0, 0, 0} |
||||
image[5][3] = {0, 0, 0} |
||||
image[6][3] = {191, 191, 191} |
||||
image[7][3] = {0, 0, 0} |
||||
|
||||
image[1][4] = {0, 0, 0} |
||||
image[2][4] = {0, 0, 0} |
||||
image[3][4] = {0, 0, 0} |
||||
image[4][4] = {196, 196, 196} |
||||
image[5][4] = {191, 191, 191} |
||||
image[6][4] = {0, 0, 0} |
||||
image[7][4] = {191, 191, 191} |
||||
|
||||
image[1][5] = {0, 0, 0} |
||||
image[2][5] = {0, 0, 0} |
||||
image[3][5] = {0, 0, 0} |
||||
image[4][5] = {191, 191, 191} |
||||
image[5][5] = {0, 0, 0} |
||||
image[6][5] = {0, 0, 0} |
||||
image[7][5] = {191, 191, 191} |
||||
|
||||
image[1][6] = {0, 0, 0} |
||||
image[2][6] = {0, 0, 0} |
||||
image[3][6] = {191, 191, 191} |
||||
image[4][6] = {0, 0, 0} |
||||
image[5][6] = {191, 191, 191} |
||||
image[6][6] = {0, 0, 0} |
||||
image[7][6] = {191, 191, 191} |
||||
|
||||
image[1][7] = {0, 0, 0} |
||||
image[2][7] = {191, 191, 191} |
||||
image[3][7] = {0, 0, 0} |
||||
image[4][7] = {0, 0, 0} |
||||
image[5][7] = {191, 191, 191} |
||||
image[6][7] = {0, 0, 0} |
||||
image[7][7] = {191, 191, 191} |
||||
|
||||
image[1][8] = {191, 191, 191} |
||||
image[2][8] = {191, 191, 191} |
||||
image[3][8] = {191, 191, 191} |
||||
image[4][8] = {191, 191, 191} |
||||
image[5][8] = {191, 191, 191} |
||||
image[6][8] = {191, 191, 191} |
||||
image[7][8] = {191, 191, 191} |
||||
|
||||
image[1][9] = {0, 0, 0} |
||||
image[2][9] = {0, 0, 0} |
||||
image[3][9] = {0, 0, 0} |
||||
image[4][9] = {0, 0, 0} |
||||
image[5][9] = {0, 0, 0} |
||||
image[6][9] = {0, 0, 0} |
||||
image[7][9] = {191, 191, 191} |
||||
|
||||
image[1][10] = {0, 0, 0} |
||||
image[2][10] = {191, 191, 191} |
||||
image[3][10] = {191, 191, 191} |
||||
image[4][10] = {191, 191, 191} |
||||
image[5][10] = {191, 191, 191} |
||||
image[6][10] = {191, 191, 191} |
||||
image[7][10] = {191, 191, 191} |
||||
|
||||
image[1][11] = {191, 191, 191} |
||||
image[2][11] = {190, 190, 190} |
||||
image[3][11] = {0, 0, 0} |
||||
image[4][11] = {0, 0, 0} |
||||
image[5][11] = {0, 0, 0} |
||||
image[6][11] = {0, 0, 0} |
||||
image[7][11] = {191, 191, 191} |
||||
|
||||
image[1][12] = {191, 191, 191} |
||||
image[2][12] = {192, 192, 192} |
||||
image[3][12] = {0, 0, 0} |
||||
image[4][12] = {191, 191, 191} |
||||
image[5][12] = {0, 0, 0} |
||||
image[6][12] = {0, 0, 0} |
||||
image[7][12] = {191, 191, 191} |
||||
|
||||
image[1][13] = {191, 191, 191} |
||||
image[2][13] = {191, 191, 191} |
||||
image[3][13] = {191, 191, 191} |
||||
image[4][13] = {191, 191, 191} |
||||
image[5][13] = {193, 193, 193} |
||||
image[6][13] = {0, 0, 0} |
||||
image[7][13] = {191, 191, 191} |
||||
|
||||
image[1][14] = {0, 0, 0} |
||||
image[2][14] = {191, 191, 191} |
||||
image[3][14] = {191, 191, 191} |
||||
image[4][14] = {0, 0, 0} |
||||
image[5][14] = {191, 191, 191} |
||||
image[6][14] = {187, 187, 187} |
||||
image[7][14] = {191, 191, 191} |
||||
|
||||
image[1][15] = {0, 0, 0} |
||||
image[2][15] = {191, 191, 191} |
||||
image[3][15] = {191, 191, 191} |
||||
image[4][15] = {191, 191, 191} |
||||
image[5][15] = {191, 191, 191} |
||||
image[6][15] = {191, 191, 191} |
||||
image[7][15] = {191, 191, 191} |
||||
|
||||
image[1][16] = {195, 195, 195} |
||||
image[2][16] = {191, 191, 191} |
||||
image[3][16] = {191, 191, 191} |
||||
image[4][16] = {191, 191, 191} |
||||
image[5][16] = {191, 191, 191} |
||||
image[6][16] = {191, 191, 191} |
||||
image[7][16] = {191, 191, 191} |
||||
|
||||
image[1][17] = {191, 191, 191} |
||||
image[2][17] = {190, 190, 190} |
||||
image[3][17] = {0, 0, 0} |
||||
image[4][17] = {0, 0, 0} |
||||
image[5][17] = {190, 190, 190} |
||||
image[6][17] = {191, 191, 191} |
||||
image[7][17] = {191, 191, 191} |
||||
|
||||
image[1][18] = {191, 191, 191} |
||||
image[2][18] = {191, 191, 191} |
||||
image[3][18] = {0, 0, 0} |
||||
image[4][18] = {0, 0, 0} |
||||
image[5][18] = {191, 191, 191} |
||||
image[6][18] = {191, 191, 191} |
||||
image[7][18] = {191, 191, 191} |
||||
|
||||
image[1][19] = {0, 0, 0} |
||||
image[2][19] = {191, 191, 191} |
||||
image[3][19] = {191, 191, 191} |
||||
image[4][19] = {191, 191, 191} |
||||
image[5][19] = {191, 191, 191} |
||||
image[6][19] = {0, 0, 0} |
||||
image[7][19] = {191, 191, 191} |
||||
|
||||
image[1][20] = {0, 0, 0} |
||||
image[2][20] = {0, 0, 0} |
||||
image[3][20] = {0, 0, 0} |
||||
image[4][20] = {0, 0, 0} |
||||
image[5][20] = {0, 0, 0} |
||||
image[6][20] = {0, 0, 0} |
||||
image[7][20] = {191, 191, 191} |
||||
|
||||
image[1][21] = {0, 0, 0} |
||||
image[2][21] = {191, 191, 191} |
||||
image[3][21] = {191, 191, 191} |
||||
image[4][21] = {191, 191, 191} |
||||
image[5][21] = {191, 191, 191} |
||||
image[6][21] = {0, 0, 0} |
||||
image[7][21] = {191, 191, 191} |
||||
|
||||
image[1][22] = {191, 191, 191} |
||||
image[2][22] = {192, 192, 192} |
||||
image[3][22] = {192, 192, 192} |
||||
image[4][22] = {192, 192, 192} |
||||
image[5][22] = {191, 191, 191} |
||||
image[6][22] = {191, 191, 191} |
||||
image[7][22] = {191, 191, 191} |
||||
|
||||
image[1][23] = {0, 0, 0} |
||||
image[2][23] = {0, 0, 0} |
||||
image[3][23] = {0, 0, 0} |
||||
image[4][23] = {0, 0, 0} |
||||
image[5][23] = {191, 191, 191} |
||||
image[6][23] = {191, 191, 191} |
||||
image[7][23] = {191, 191, 191} |
||||
|
||||
image[1][24] = {191, 191, 191} |
||||
image[2][24] = {191, 191, 191} |
||||
image[3][24] = {191, 191, 191} |
||||
image[4][24] = {191, 191, 191} |
||||
image[5][24] = {191, 191, 191} |
||||
image[6][24] = {0, 0, 0} |
||||
image[7][24] = {191, 191, 191} |
||||
|
||||
image[1][25] = {192, 192, 192} |
||||
image[2][25] = {192, 192, 192} |
||||
image[3][25] = {192, 192, 192} |
||||
image[4][25] = {192, 192, 192} |
||||
image[5][25] = {0, 0, 0} |
||||
image[6][25] = {0, 0, 0} |
||||
image[7][25] = {191, 191, 191} |
||||
|
||||
image[1][26] = {0, 0, 0} |
||||
image[2][26] = {254, 210, 15} |
||||
image[3][26] = {251, 195, 20} |
||||
image[4][26] = {249, 179, 23} |
||||
image[5][26] = {249, 163, 26} |
||||
image[6][26] = {244, 150, 28} |
||||
image[7][26] = {191, 191, 191} |
||||
|
||||
image[1][27] = {255, 223, 11} |
||||
image[2][27] = {254, 211, 18} |
||||
image[3][27] = {244, 196, 36} |
||||
image[4][27] = {242, 181, 41} |
||||
image[5][27] = {240, 166, 41} |
||||
image[6][27] = {237, 152, 46} |
||||
image[7][27] = {191, 191, 191} |
||||
|
||||
image[1][28] = {255, 221, 12} |
||||
image[2][28] = {253, 210, 20} |
||||
image[3][28] = {0, 0, 0} |
||||
image[4][28] = {249, 179, 23} |
||||
image[5][28] = {0, 0, 0} |
||||
image[6][28] = {0, 0, 0} |
||||
image[7][28] = {191, 191, 191} |
||||
|
||||
image[1][29] = {252, 222, 12} |
||||
image[2][29] = {253, 210, 18} |
||||
image[3][29] = {252, 195, 20} |
||||
image[4][29] = {249, 179, 23} |
||||
image[5][29] = {0, 0, 0} |
||||
image[6][29] = {0, 0, 0} |
||||
image[7][29] = {191, 191, 191} |
||||
|
||||
image[1][30] = {0, 0, 0} |
||||
image[2][30] = {253, 210, 18} |
||||
image[3][30] = {251, 195, 20} |
||||
image[4][30] = {248, 179, 23} |
||||
image[5][30] = {0, 0, 0} |
||||
image[6][30] = {0, 0, 0} |
||||
image[7][30] = {191, 191, 191} |
||||
|
||||
image[1][31] = {0, 0, 0} |
||||
image[2][31] = {0, 0, 0} |
||||
image[3][31] = {0, 0, 0} |
||||
image[4][31] = {0, 0, 0} |
||||
image[5][31] = {0, 0, 0} |
||||
image[6][31] = {0, 0, 0} |
||||
image[7][31] = {191, 191, 191} |
||||
|
||||
image[1][32] = {0, 0, 0} |
||||
image[2][32] = {253, 210, 18} |
||||
image[3][32] = {251, 195, 20} |
||||
image[4][32] = {249, 179, 23} |
||||
image[5][32] = {249, 163, 26} |
||||
image[6][32] = {244, 150, 28} |
||||
image[7][32] = {191, 191, 191} |
||||
|
||||
image[1][33] = {0, 0, 0} |
||||
image[2][33] = {0, 0, 0} |
||||
image[3][33] = {0, 0, 0} |
||||
image[4][33] = {0, 0, 0} |
||||
image[5][33] = {0, 0, 0} |
||||
image[6][33] = {0, 0, 0} |
||||
image[7][33] = {191, 191, 191} |
||||
|
||||
image[1][34] = {0, 0, 0} |
||||
image[2][34] = {253, 210, 17} |
||||
image[3][34] = {251, 195, 20} |
||||
image[4][34] = {249, 179, 23} |
||||
image[5][34] = {249, 163, 26} |
||||
image[6][34] = {244, 150, 28} |
||||
image[7][34] = {191, 191, 191} |
||||
|
||||
image[1][35] = {0, 0, 0} |
||||
image[2][35] = {0, 0, 0} |
||||
image[3][35] = {0, 0, 0} |
||||
image[4][35] = {0, 0, 0} |
||||
image[5][35] = {250, 162, 26} |
||||
image[6][35] = {244, 150, 28} |
||||
image[7][35] = {191, 191, 191} |
||||
|
||||
image[1][36] = {0, 0, 0} |
||||
image[2][36] = {0, 0, 0} |
||||
image[3][36] = {0, 0, 0} |
||||
image[4][36] = {0, 0, 0} |
||||
image[5][36] = {249, 163, 26} |
||||
image[6][36] = {244, 150, 28} |
||||
image[7][36] = {191, 191, 191} |
||||
|
||||
image[1][37] = {0, 0, 0} |
||||
image[2][37] = {0, 0, 0} |
||||
image[3][37] = {252, 196, 21} |
||||
image[4][37] = {248, 179, 23} |
||||
image[5][37] = {0, 0, 0} |
||||
image[6][37] = {0, 0, 0} |
||||
image[7][37] = {191, 191, 191} |
||||
|
||||
image[1][38] = {0, 0, 0} |
||||
image[2][38] = {253, 210, 18} |
||||
image[3][38] = {0, 0, 0} |
||||
image[4][38] = {0, 0, 0} |
||||
image[5][38] = {249, 163, 26} |
||||
image[6][38] = {0, 0, 0} |
||||
image[7][38] = {191, 191, 191} |
||||
|
||||
image[1][39] = {249, 223, 14} |
||||
image[2][39] = {0, 0, 0} |
||||
image[3][39] = {244, 193, 22} |
||||
image[4][39] = {247, 187, 41} |
||||
image[5][39] = {0, 0, 0} |
||||
image[6][39] = {245, 149, 28} |
||||
image[7][39] = {191, 191, 191} |
||||
|
||||
image[1][40] = {252, 222, 14} |
||||
image[2][40] = {0, 0, 0} |
||||
image[3][40] = {249, 196, 18} |
||||
image[4][40] = {249, 179, 19} |
||||
image[5][40] = {0, 0, 0} |
||||
image[6][40] = {0, 0, 0} |
||||
image[7][40] = {191, 191, 191} |
||||
|
||||
image[1][41] = {255, 222, 13} |
||||
image[2][41] = {250, 214, 18} |
||||
image[3][41] = {0, 0, 0} |
||||
image[4][41] = {0, 0, 0} |
||||
image[5][41] = {247, 164, 22} |
||||
image[6][41] = {244, 147, 32} |
||||
image[7][41] = {191, 191, 191} |
||||
|
||||
image[1][42] = {0, 0, 0} |
||||
image[2][42] = {255, 209, 17} |
||||
image[3][42] = {251, 195, 20} |
||||
image[4][42] = {249, 179, 23} |
||||
image[5][42] = {247, 164, 26} |
||||
image[6][42] = {0, 0, 0} |
||||
image[7][42] = {191, 191, 191} |
||||
|
||||
image[1][43] = {0, 0, 0} |
||||
image[2][43] = {249, 213, 15} |
||||
image[3][43] = {0, 0, 0} |
||||
image[4][43] = {0, 0, 0} |
||||
image[5][43] = {0, 0, 0} |
||||
image[6][43] = {0, 0, 0} |
||||
image[7][43] = {191, 191, 191} |
||||
|
||||
image[1][44] = {249, 221, 15} |
||||
image[2][44] = {244, 211, 18} |
||||
image[3][44] = {0, 0, 0} |
||||
image[4][44] = {0, 0, 0} |
||||
image[5][44] = {0, 0, 0} |
||||
image[6][44] = {0, 0, 0} |
||||
image[7][44] = {191, 191, 191} |
||||
|
||||
image[1][45] = {255, 221, 12} |
||||
image[2][45] = {253, 210, 18} |
||||
image[3][45] = {251, 195, 20} |
||||
image[4][45] = {249, 179, 23} |
||||
image[5][45] = {249, 163, 26} |
||||
image[6][45] = {245, 149, 26} |
||||
image[7][45] = {191, 191, 191} |
||||
|
||||
image[1][46] = {255, 221, 12} |
||||
image[2][46] = {251, 211, 17} |
||||
image[3][46] = {0, 0, 0} |
||||
image[4][46] = {0, 0, 0} |
||||
image[5][46] = {0, 0, 0} |
||||
image[6][46] = {0, 0, 0} |
||||
image[7][46] = {191, 191, 191} |
||||
|
||||
image[1][47] = {255, 221, 12} |
||||
image[2][47] = {0, 0, 0} |
||||
image[3][47] = {0, 0, 0} |
||||
image[4][47] = {0, 0, 0} |
||||
image[5][47] = {0, 0, 0} |
||||
image[6][47] = {0, 0, 0} |
||||
image[7][47] = {0, 0, 0} |
||||
|
||||
image[1][48] = {0, 0, 0} |
||||
image[2][48] = {0, 0, 0} |
||||
image[3][48] = {0, 0, 0} |
||||
image[4][48] = {0, 0, 0} |
||||
image[5][48] = {0, 0, 0} |
||||
image[6][48] = {0, 0, 0} |
||||
image[7][48] = {0, 0, 0} |
||||
|
||||
--[[ |
||||
use SERVOn_FUNCTION 94 for LED. We can control up to 16 separate strips of LEDs |
||||
by putting them on different channels |
||||
--]] |
||||
local chan = SRV_Channels:find_channel(94) |
||||
|
||||
if not chan then |
||||
gcs:send_text(6, "LEDs: channel not set") |
||||
return |
||||
end |
||||
|
||||
-- find_channel returns 0 to 15, convert to 1 to 16 |
||||
chan = chan + 1 |
||||
|
||||
gcs:send_text(6, "LEDs: chan=" .. tostring(chan)) |
||||
|
||||
-- initialisation code |
||||
--serialLED:set_num_neopixel(chan, matrix_x * matrix_y) |
||||
serialLED:set_num_profiled(chan, matrix_x * matrix_y) |
||||
|
||||
local offset = 8; |
||||
|
||||
local function display_image(image_in,offset_in,brightness_in) |
||||
local im_offset = 0 |
||||
if offset_in then |
||||
im_offset = offset_in |
||||
end |
||||
local brightness = 1 |
||||
if brightness_in then |
||||
brightness = brightness_in |
||||
end |
||||
|
||||
local i |
||||
local j |
||||
|
||||
for i = 1, 48 do |
||||
local x_index = i + im_offset |
||||
if x_index >= 1 and x_index <= matrix_x then |
||||
for j = 1, matrix_y do |
||||
serialLED:set_RGB(chan, id[j][x_index], math.floor(image_in[j][i][1]*brightness), math.floor(image_in[j][i][2]*brightness), math.floor(image_in[j][i][3]*brightness)) |
||||
end |
||||
end |
||||
end |
||||
|
||||
end |
||||
|
||||
|
||||
function update_LEDs() |
||||
|
||||
serialLED:set_RGB(chan, -1, 0, 0, 0) |
||||
|
||||
display_image(image,offset,0.05) |
||||
|
||||
serialLED:send(chan) |
||||
|
||||
offset = offset - 1 |
||||
|
||||
-- scroll until it is off the left edge |
||||
if offset < - 48 - 8 then |
||||
-- start with the stuff off the right edge of the display |
||||
offset = 8 |
||||
end |
||||
|
||||
|
||||
return update_LEDs, 100 |
||||
end |
||||
|
||||
return update_LEDs, 1000 |
@ -0,0 +1,256 @@
@@ -0,0 +1,256 @@
|
||||
--[[ |
||||
Script to control LED strips based on the roll of the aircraft. This is an example to demonstrate |
||||
the LED interface for WS2812 LEDs |
||||
--]] |
||||
|
||||
--[[ |
||||
for this demo we will use a single strip with 30 LEDs |
||||
--]] |
||||
local matrix_x = 7 |
||||
local matrix_y = 7 |
||||
|
||||
-- matrix to convert from x y pos to location in the strip |
||||
local id = {} |
||||
-- because my strips go diagonally to get the led's closer together this is a odd ordering |
||||
id[1] = {} |
||||
id[1][1] = 21 |
||||
id[1][2] = 20 |
||||
id[1][3] = 10 |
||||
id[1][4] = 9 |
||||
id[1][5] = 3 |
||||
id[1][6] = 2 |
||||
id[1][7] = 0 |
||||
|
||||
id[2] = {} |
||||
id[2][1] = 33 |
||||
id[2][2] = 22 |
||||
id[2][3] = 19 |
||||
id[2][4] = 11 |
||||
id[2][5] = 8 |
||||
id[2][6] = 4 |
||||
id[2][7] = 1 |
||||
|
||||
id[3] = {} |
||||
id[3][1] = 34 |
||||
id[3][2] = 32 |
||||
id[3][3] = 23 |
||||
id[3][4] = 18 |
||||
id[3][5] = 12 |
||||
id[3][6] = 7 |
||||
id[3][7] = 5 |
||||
|
||||
id[4] = {} |
||||
id[4][1] = 42 |
||||
id[4][2] = 35 |
||||
id[4][3] = 31 |
||||
id[4][4] = 24 |
||||
id[4][5] = 17 |
||||
id[4][6] = 13 |
||||
id[4][7] = 6 |
||||
|
||||
id[5] = {} |
||||
id[5][1] = 43 |
||||
id[5][2] = 41 |
||||
id[5][3] = 36 |
||||
id[5][4] = 30 |
||||
id[5][5] = 25 |
||||
id[5][6] = 16 |
||||
id[5][7] = 14 |
||||
|
||||
id[6] = {} |
||||
id[6][1] = 47 |
||||
id[6][2] = 44 |
||||
id[6][3] = 40 |
||||
id[6][4] = 37 |
||||
id[6][5] = 29 |
||||
id[6][6] = 26 |
||||
id[6][7] = 15 |
||||
|
||||
id[7] = {} |
||||
id[7][1] = 48 |
||||
id[7][2] = 46 |
||||
id[7][3] = 45 |
||||
id[7][4] = 39 |
||||
id[7][5] = 38 |
||||
id[7][6] = 28 |
||||
id[7][7] = 27 |
||||
|
||||
-- https://github.com/noopkat/oled-font-5x7/blob/master/oled-font-5x7.js |
||||
font = {} |
||||
font[' '] = {0x00, 0x00, 0x00, 0x00, 0x00} -- // space |
||||
font['!'] = {0x00, 0x00, 0x5F, 0x00, 0x00} -- // ! |
||||
font['"'] = {0x00, 0x07, 0x00, 0x07, 0x00} -- // " |
||||
font['#'] = {0x14, 0x7F, 0x14, 0x7F, 0x14} -- // # |
||||
font['$'] = {0x24, 0x2A, 0x7F, 0x2A, 0x12} -- // $ |
||||
font['%'] = {0x23, 0x13, 0x08, 0x64, 0x62} -- // % |
||||
font['&'] = {0x36, 0x49, 0x55, 0x22, 0x50} -- // & |
||||
font['('] = {0x00, 0x1C, 0x22, 0x41, 0x00} -- // ( |
||||
font[')'] = {0x00, 0x41, 0x22, 0x1C, 0x00} -- // ) |
||||
font['*'] = {0x08, 0x2A, 0x1C, 0x2A, 0x08} -- // * |
||||
font['+'] = {0x08, 0x08, 0x3E, 0x08, 0x08} -- // + |
||||
font[','] = {0x00, 0x50, 0x30, 0x00, 0x00} -- // , |
||||
font['-'] = {0x08, 0x08, 0x08, 0x08, 0x08} -- // - |
||||
font['.'] = {0x00, 0x60, 0x60, 0x00, 0x00} -- // . |
||||
font['/'] = {0x20, 0x10, 0x08, 0x04, 0x02} -- // / |
||||
font['0'] = {0x3E, 0x51, 0x49, 0x45, 0x3E} -- // 0 |
||||
font['1'] = {0x00, 0x42, 0x7F, 0x40, 0x00} -- // 1 |
||||
font['2'] = {0x42, 0x61, 0x51, 0x49, 0x46} -- // 2 |
||||
font['3'] = {0x21, 0x41, 0x45, 0x4B, 0x31} -- // 3 |
||||
font['4'] = {0x18, 0x14, 0x12, 0x7F, 0x10} -- // 4 |
||||
font['5'] = {0x27, 0x45, 0x45, 0x45, 0x39} -- // 5 |
||||
font['6'] = {0x3C, 0x4A, 0x49, 0x49, 0x30} -- // 6 |
||||
font['7'] = {0x01, 0x71, 0x09, 0x05, 0x03} -- // 7 |
||||
font['8'] = {0x36, 0x49, 0x49, 0x49, 0x36} -- // 8 |
||||
font['9'] = {0x06, 0x49, 0x49, 0x29, 0x1E} -- // 9 |
||||
font[':'] = {0x00, 0x36, 0x36, 0x00, 0x00} -- // : |
||||
font[';'] = {0x00, 0x56, 0x36, 0x00, 0x00} -- // ; |
||||
font['<'] = {0x00, 0x08, 0x14, 0x22, 0x41} -- // < |
||||
font['='] = {0x14, 0x14, 0x14, 0x14, 0x14} -- // = |
||||
font['>'] = {0x41, 0x22, 0x14, 0x08, 0x00} -- // > |
||||
font['?'] = {0x02, 0x01, 0x51, 0x09, 0x06} -- // ? |
||||
font['@'] = {0x32, 0x49, 0x79, 0x41, 0x3E} -- // @ |
||||
font['A'] = {0x7E, 0x11, 0x11, 0x11, 0x7E} -- // A |
||||
font['B'] = {0x7F, 0x49, 0x49, 0x49, 0x36} -- // B |
||||
font['C'] = {0x3E, 0x41, 0x41, 0x41, 0x22} -- // C |
||||
font['D'] = {0x7F, 0x41, 0x41, 0x22, 0x1C} -- // D |
||||
font['E'] = {0x7F, 0x49, 0x49, 0x49, 0x41} -- // E |
||||
font['F'] = {0x7F, 0x09, 0x09, 0x01, 0x01} -- // F |
||||
font['G'] = {0x3E, 0x41, 0x41, 0x51, 0x32} -- // G |
||||
font['H'] = {0x7F, 0x08, 0x08, 0x08, 0x7F} -- // H |
||||
font['I'] = {0x00, 0x41, 0x7F, 0x41, 0x00} -- // I |
||||
font['J'] = {0x20, 0x40, 0x41, 0x3F, 0x01} -- // J |
||||
font['K'] = {0x7F, 0x08, 0x14, 0x22, 0x41} -- // K |
||||
font['L'] = {0x7F, 0x40, 0x40, 0x40, 0x40} -- // L |
||||
font['M'] = {0x7F, 0x02, 0x04, 0x02, 0x7F} -- // M |
||||
font['N'] = {0x7F, 0x04, 0x08, 0x10, 0x7F} -- // N |
||||
font['O'] = {0x3E, 0x41, 0x41, 0x41, 0x3E} -- // O |
||||
font['P'] = {0x7F, 0x09, 0x09, 0x09, 0x06} -- // P |
||||
font['Q'] = {0x3E, 0x41, 0x51, 0x21, 0x5E} -- // Q |
||||
font['R'] = {0x7F, 0x09, 0x19, 0x29, 0x46} -- // R |
||||
font['S'] = {0x46, 0x49, 0x49, 0x49, 0x31} -- // S |
||||
font['T'] = {0x01, 0x01, 0x7F, 0x01, 0x01} -- // T |
||||
font['U'] = {0x3F, 0x40, 0x40, 0x40, 0x3F} -- // U |
||||
font['V'] = {0x1F, 0x20, 0x40, 0x20, 0x1F} -- // V |
||||
font['W'] = {0x7F, 0x20, 0x18, 0x20, 0x7F} -- // W |
||||
font['X'] = {0x63, 0x14, 0x08, 0x14, 0x63} -- // X |
||||
font['Y'] = {0x03, 0x04, 0x78, 0x04, 0x03} -- // Y |
||||
font['Z'] = {0x61, 0x51, 0x49, 0x45, 0x43} -- // Z |
||||
font['['] = {0x00, 0x00, 0x7F, 0x41, 0x41} -- // [ |
||||
font[']'] = {0x41, 0x41, 0x7F, 0x00, 0x00} -- // ] |
||||
font['^'] = {0x04, 0x02, 0x01, 0x02, 0x04} -- // ^ |
||||
font['_'] = {0x40, 0x40, 0x40, 0x40, 0x40} -- // _ |
||||
font['a'] = {0x20, 0x54, 0x54, 0x54, 0x78} -- // a |
||||
font['b'] = {0x7F, 0x48, 0x44, 0x44, 0x38} -- // b |
||||
font['c'] = {0x38, 0x44, 0x44, 0x44, 0x20} -- // c |
||||
font['d'] = {0x38, 0x44, 0x44, 0x48, 0x7F} -- // d |
||||
font['e'] = {0x38, 0x54, 0x54, 0x54, 0x18} -- // e |
||||
font['f'] = {0x08, 0x7E, 0x09, 0x01, 0x02} -- // f |
||||
font['g'] = {0x08, 0x14, 0x54, 0x54, 0x3C} -- // g |
||||
font['h'] = {0x7F, 0x08, 0x04, 0x04, 0x78} -- // h |
||||
font['i'] = {0x00, 0x44, 0x7D, 0x40, 0x00} -- // i |
||||
font['j'] = {0x20, 0x40, 0x44, 0x3D, 0x00} -- // j |
||||
font['k'] = {0x00, 0x7F, 0x10, 0x28, 0x44} -- // k |
||||
font['l'] = {0x00, 0x41, 0x7F, 0x40, 0x00} -- // l |
||||
font['m'] = {0x7C, 0x04, 0x18, 0x04, 0x78} -- // m |
||||
font['n'] = {0x7C, 0x08, 0x04, 0x04, 0x78} -- // n |
||||
font['o'] = {0x38, 0x44, 0x44, 0x44, 0x38} -- // o |
||||
font['p'] = {0x7C, 0x14, 0x14, 0x14, 0x08} -- // p |
||||
font['q'] = {0x08, 0x14, 0x14, 0x18, 0x7C} -- // q |
||||
font['r'] = {0x7C, 0x08, 0x04, 0x04, 0x08} -- // r |
||||
font['s'] = {0x48, 0x54, 0x54, 0x54, 0x20} -- // s |
||||
font['t'] = {0x04, 0x3F, 0x44, 0x40, 0x20} -- // t |
||||
font['u'] = {0x3C, 0x40, 0x40, 0x20, 0x7C} -- // u |
||||
font['v'] = {0x1C, 0x20, 0x40, 0x20, 0x1C} -- // v |
||||
font['w'] = {0x3C, 0x40, 0x30, 0x40, 0x3C} -- // w |
||||
font['x'] = {0x44, 0x28, 0x10, 0x28, 0x44} -- // x |
||||
font['y'] = {0x0C, 0x50, 0x50, 0x50, 0x3C} -- // y |
||||
font['z'] = {0x44, 0x64, 0x54, 0x4C, 0x44} -- // z |
||||
font['{'] = {0x00, 0x08, 0x36, 0x41, 0x00} -- // { |
||||
font['|'] = {0x00, 0x00, 0x7F, 0x00, 0x00} -- // | |
||||
font['}'] = {0x00, 0x41, 0x36, 0x08, 0x00} -- // } |
||||
|
||||
--[[ |
||||
use SERVOn_FUNCTION 94 for LED. We can control up to 16 separate strips of LEDs |
||||
by putting them on different channels |
||||
--]] |
||||
local chan = SRV_Channels:find_channel(94) |
||||
|
||||
if not chan then |
||||
gcs:send_text(6, "LEDs: channel not set") |
||||
return |
||||
end |
||||
|
||||
-- find_channel returns 0 to 15, convert to 1 to 16 |
||||
chan = chan + 1 |
||||
|
||||
gcs:send_text(6, "LEDs: chan=" .. tostring(chan)) |
||||
|
||||
-- initialisation code |
||||
--serialLED:set_num_neopixel(chan, matrix_x * matrix_y) |
||||
serialLED:set_num_profiled(chan, matrix_x * matrix_y) |
||||
|
||||
local offset = 8; |
||||
local text_string = "ArduPilot" |
||||
|
||||
local function display_char(char,r,g,b,offset_in) |
||||
local char_offset = 0 |
||||
if offset_in then |
||||
char_offset = offset_in |
||||
end |
||||
if char_offset > matrix_x then |
||||
return |
||||
end |
||||
if char_offset < 1 - 5 then |
||||
return |
||||
end |
||||
|
||||
local i |
||||
local j |
||||
|
||||
for i = 1, 5 do |
||||
local x_index = i + char_offset |
||||
if x_index >= 1 and x_index <= matrix_x then |
||||
local font_colum = font[char][i] |
||||
for j = 1, 7 do |
||||
if (font_colum & 1) == 1 then |
||||
serialLED:set_RGB(chan, id[j][x_index], r, g, b) |
||||
end |
||||
font_colum = font_colum >> 1 |
||||
end |
||||
end |
||||
end |
||||
|
||||
end |
||||
|
||||
local function display_string(string,r,g,b,offset_in) |
||||
local str_offset = 0 |
||||
local i |
||||
for i = 1, string:len() do |
||||
display_char(string:sub(i,i),r,g,b,str_offset + offset_in) |
||||
str_offset = str_offset + 6 |
||||
end |
||||
end |
||||
|
||||
function update_LEDs() |
||||
|
||||
serialLED:set_RGB(chan, -1, 0, 0, 0) |
||||
|
||||
display_string(text_string,100,0,0,offset) |
||||
|
||||
serialLED:send(chan) |
||||
|
||||
offset = offset - 1 |
||||
|
||||
-- scroll until it is off the left edge |
||||
if offset < -text_string:len()*6 then |
||||
-- start with the stuff off the right edge of the display |
||||
offset = 8 |
||||
|
||||
text_string = tostring(math.floor(math.deg(ahrs:get_yaw()))) |
||||
end |
||||
|
||||
return update_LEDs, 100 |
||||
end |
||||
|
||||
return update_LEDs, 1000 |
||||
|
Loading…
Reference in new issue